Skip to main content
formatted inline code, moved problem description to the top, corrected spelling
Source Link
Gustavo Maciel
  • 5.2k
  • 3
  • 27
  • 43

I'm trying to make a respawn point for my car to jump back to if it presses a button. I can see, using the Print() lines, that all the variables are correct and the methods are being triggered when expected.

But the car doesn't go back to the spawnpoint like I want it to. The velocity part seems to take effect and work ok, but the rotation and position part does nothing.

I tried several different variations of this code (ie. GetComponent<> and setting a public player variable (even though I am already in the player with this script)).

Like I said I tried making a public Player and setting the transform p and r on that. I also tried GetComponentByParent<Transform> and setting like that. I've tried a few other variations of that too. And I get the same results.

Here is the bit of code I think is relevant, if you actually need to see more please let me know.

  public void OnTriggerExit(Collider other)
{
    if (other.gameObject.tag == "RespawnTrack")
    {
        print("respawn point added upon Trigger Exit");
        recordedTransformAtRespawnTrack = transform;
        recordedVelocityAtRespawnTrack = rb.velocity * 0.25f;
        print("rotation was: X,Y,Z=" + recordedTransformAtRespawnTrack.rotation.x + " , " + recordedTransformAtRespawnTrack.rotation.y + " , " + recordedTransformAtRespawnTrack.rotation.z);
        print("position was: X,Y,Z=" + recordedTransformAtRespawnTrack.position.x + " , " + recordedTransformAtRespawnTrack.position.y + " , " + recordedTransformAtRespawnTrack.position.z);
    }
}

public void CheckToRespawnCar()
{
    if (isRacing)
    {

        if (CrossPlatformInputManager.GetButtonDown("Jump"))
        {
            print("RESPAWN TRIGGERED BY PRESSING BUTTON");
            
            transform.position = recordedTransformAtRespawnTrack.position;
            transform.rotation = recordedTransformAtRespawnTrack.rotation;
          
            rb.velocity = recordedVelocityAtRespawnTrack;
            
        }

    }
}

I'm trying to make a respawn point for my car to jump back to if it presses a button. I can see, using the Print() lines, that all the variables are correct and the methods are being triggered when expected.

But the car doesn't go back to the spawnpoint like I want it to. The velocity part seems to take effect and work ok, but the rotation and position part does nothing.

I tried several different variations of this code (ie. GetComponent<> and setting a public player variable (even though I am already in the player with this script)).

Like I said I tried making a public Player and setting the transform p and r on that. I also tried GetComponentByParent<Transform> and setting like that. I've tried a few other variations of that too. And I get the same results.

Here is the bit of code I think is relevant, if you actually need to see more please let me know.

  public void OnTriggerExit(Collider other)
{
    if (other.gameObject.tag == "RespawnTrack")
    {
        print("respawn point added upon Trigger Exit");
        recordedTransformAtRespawnTrack = transform;
        recordedVelocityAtRespawnTrack = rb.velocity * 0.25f;
        print("rotation was: X,Y,Z=" + recordedTransformAtRespawnTrack.rotation.x + " , " + recordedTransformAtRespawnTrack.rotation.y + " , " + recordedTransformAtRespawnTrack.rotation.z);
        print("position was: X,Y,Z=" + recordedTransformAtRespawnTrack.position.x + " , " + recordedTransformAtRespawnTrack.position.y + " , " + recordedTransformAtRespawnTrack.position.z);
    }
}

public void CheckToRespawnCar()
{
    if (isRacing)
    {

        if (CrossPlatformInputManager.GetButtonDown("Jump"))
        {
            print("RESPAWN TRIGGERED BY PRESSING BUTTON");
            
            transform.position = recordedTransformAtRespawnTrack.position;
            transform.rotation = recordedTransformAtRespawnTrack.rotation;
          
            rb.velocity = recordedVelocityAtRespawnTrack;
            
        }

    }
}

I'm trying to make a respawn point for my car to jump back to if it presses a button. I can see, using the Print() lines, that all the variables are correct and the methods are being triggered when expected.

But the car doesn't go back to the spawnpoint like I want it to. The velocity part seems to take effect and work ok, but the rotation and position part does nothing.

I tried several different variations of this code (ie. GetComponent<> and setting a public player variable (even though I am already in the player with this script)).

Like I said I tried making a public Player and setting the transform p and r on that. I also tried GetComponentByParent<Transform> and setting like that. I've tried a few other variations of that too. And I get the same results.

Here is the bit of code I think is relevant, if you actually need to see more please let me know.

public void OnTriggerExit(Collider other)
{
    if (other.gameObject.tag == "RespawnTrack")
    {
        print("respawn point added upon Trigger Exit");
        recordedTransformAtRespawnTrack = transform;
        recordedVelocityAtRespawnTrack = rb.velocity * 0.25f;
        print("rotation was: X,Y,Z=" + recordedTransformAtRespawnTrack.rotation.x + " , " + recordedTransformAtRespawnTrack.rotation.y + " , " + recordedTransformAtRespawnTrack.rotation.z);
        print("position was: X,Y,Z=" + recordedTransformAtRespawnTrack.position.x + " , " + recordedTransformAtRespawnTrack.position.y + " , " + recordedTransformAtRespawnTrack.position.z);
    }
}

public void CheckToRespawnCar()
{
    if (isRacing)
    {

        if (CrossPlatformInputManager.GetButtonDown("Jump"))
        {
            print("RESPAWN TRIGGERED BY PRESSING BUTTON");
            
            transform.position = recordedTransformAtRespawnTrack.position;
            transform.rotation = recordedTransformAtRespawnTrack.rotation;
          
            rb.velocity = recordedVelocityAtRespawnTrack;
            
        }

    }
}
formatted inline code, moved problem description to the top, corrected spelling
Source Link

This one is wierd, i just cant figure it out. I tried several different variations of this code (ie. GetComponent<> and setting a public player variable (even though I am already in the player with this script)).

I'm trying to make a respawn point for my car to jump back to if it presses a button. I can see, using the Print() lines, that all the variables are correct and the methods are being triggered when expected.

But the car doesntdoesn't go back to the spawnpoint like I want it to. The velocity part seems to take effect and work ok, but the rotation and position part does nothing.

I tried several different variations of this code (ie. GetComponent<> and setting a public player variable (even though I am already in the player with this script)).

Like I said I tried making a public Player and setting the transform p and r on that. I also tried GetComponentByParentGetComponentByParent<Transform> and setting like that. I've tried a few other variations of that too. And I get the same results.

Here is the bit of code iI think is relevant  , if you actually need to see more please let me know. Thanks:

  public void OnTriggerExit(Collider other)
{
    if (other.gameObject.tag == "RespawnTrack")
    {
        print("respawn point added upon Trigger Exit");
        recordedTransformAtRespawnTrack = transform;
        recordedVelocityAtRespawnTrack = rb.velocity * 0.25f;
        print("rotation was: X,Y,Z=" + recordedTransformAtRespawnTrack.rotation.x + " , " + recordedTransformAtRespawnTrack.rotation.y + " , " + recordedTransformAtRespawnTrack.rotation.z);
        print("position was: X,Y,Z=" + recordedTransformAtRespawnTrack.position.x + " , " + recordedTransformAtRespawnTrack.position.y + " , " + recordedTransformAtRespawnTrack.position.z);
    }
}

public void CheckToRespawnCar()
{
    if (isRacing)
    {

        if (CrossPlatformInputManager.GetButtonDown("Jump"))
        {
            print("RESPAWN TRIGGERED BY PRESSING BUTTON");
            
            transform.position = recordedTransformAtRespawnTrack.position;
            transform.rotation = recordedTransformAtRespawnTrack.rotation;
          
            rb.velocity = recordedVelocityAtRespawnTrack;
            
        }

    }
}

This one is wierd, i just cant figure it out. I tried several different variations of this code (ie. GetComponent<> and setting a public player variable (even though I am already in the player with this script)).

I'm trying to make a respawn point for my car to jump back to if it presses a button. I can see, using the Print() lines, that all the variables are correct and the methods are being triggered when expected.

But the car doesnt go back to the spawnpoint like I want it to. The velocity part seems to take effect and work ok, but the rotation and position part does nothing.

Like I said I tried making a public Player and setting the transform p and r on that. I also tried GetComponentByParent and setting like that. I've tried a few other variations of that too. And I get the same results.

Here is the bit of code i think is relevant  , if you actually need to see more please let me know. Thanks:

  public void OnTriggerExit(Collider other)
{
    if (other.gameObject.tag == "RespawnTrack")
    {
        print("respawn point added upon Trigger Exit");
        recordedTransformAtRespawnTrack = transform;
        recordedVelocityAtRespawnTrack = rb.velocity * 0.25f;
        print("rotation was: X,Y,Z=" + recordedTransformAtRespawnTrack.rotation.x + " , " + recordedTransformAtRespawnTrack.rotation.y + " , " + recordedTransformAtRespawnTrack.rotation.z);
        print("position was: X,Y,Z=" + recordedTransformAtRespawnTrack.position.x + " , " + recordedTransformAtRespawnTrack.position.y + " , " + recordedTransformAtRespawnTrack.position.z);
    }
}

public void CheckToRespawnCar()
{
    if (isRacing)
    {

        if (CrossPlatformInputManager.GetButtonDown("Jump"))
        {
            print("RESPAWN TRIGGERED BY PRESSING BUTTON");
            
            transform.position = recordedTransformAtRespawnTrack.position;
            transform.rotation = recordedTransformAtRespawnTrack.rotation;
          
            rb.velocity = recordedVelocityAtRespawnTrack;
            
        }

    }
}

I'm trying to make a respawn point for my car to jump back to if it presses a button. I can see, using the Print() lines, that all the variables are correct and the methods are being triggered when expected.

But the car doesn't go back to the spawnpoint like I want it to. The velocity part seems to take effect and work ok, but the rotation and position part does nothing.

I tried several different variations of this code (ie. GetComponent<> and setting a public player variable (even though I am already in the player with this script)).

Like I said I tried making a public Player and setting the transform p and r on that. I also tried GetComponentByParent<Transform> and setting like that. I've tried a few other variations of that too. And I get the same results.

Here is the bit of code I think is relevant, if you actually need to see more please let me know.

  public void OnTriggerExit(Collider other)
{
    if (other.gameObject.tag == "RespawnTrack")
    {
        print("respawn point added upon Trigger Exit");
        recordedTransformAtRespawnTrack = transform;
        recordedVelocityAtRespawnTrack = rb.velocity * 0.25f;
        print("rotation was: X,Y,Z=" + recordedTransformAtRespawnTrack.rotation.x + " , " + recordedTransformAtRespawnTrack.rotation.y + " , " + recordedTransformAtRespawnTrack.rotation.z);
        print("position was: X,Y,Z=" + recordedTransformAtRespawnTrack.position.x + " , " + recordedTransformAtRespawnTrack.position.y + " , " + recordedTransformAtRespawnTrack.position.z);
    }
}

public void CheckToRespawnCar()
{
    if (isRacing)
    {

        if (CrossPlatformInputManager.GetButtonDown("Jump"))
        {
            print("RESPAWN TRIGGERED BY PRESSING BUTTON");
            
            transform.position = recordedTransformAtRespawnTrack.position;
            transform.rotation = recordedTransformAtRespawnTrack.rotation;
          
            rb.velocity = recordedVelocityAtRespawnTrack;
            
        }

    }
}
Source Link
Big T Larrity
  • 1.4k
  • 4
  • 31
  • 61

Transform.position is being changed, but character is not moving back to it when told

This one is wierd, i just cant figure it out. I tried several different variations of this code (ie. GetComponent<> and setting a public player variable (even though I am already in the player with this script)).

I'm trying to make a respawn point for my car to jump back to if it presses a button. I can see, using the Print() lines, that all the variables are correct and the methods are being triggered when expected.

But the car doesnt go back to the spawnpoint like I want it to. The velocity part seems to take effect and work ok, but the rotation and position part does nothing.

Like I said I tried making a public Player and setting the transform p and r on that. I also tried GetComponentByParent and setting like that. I've tried a few other variations of that too. And I get the same results.

Here is the bit of code i think is relevant , if you actually need to see more please let me know. Thanks:

  public void OnTriggerExit(Collider other)
{
    if (other.gameObject.tag == "RespawnTrack")
    {
        print("respawn point added upon Trigger Exit");
        recordedTransformAtRespawnTrack = transform;
        recordedVelocityAtRespawnTrack = rb.velocity * 0.25f;
        print("rotation was: X,Y,Z=" + recordedTransformAtRespawnTrack.rotation.x + " , " + recordedTransformAtRespawnTrack.rotation.y + " , " + recordedTransformAtRespawnTrack.rotation.z);
        print("position was: X,Y,Z=" + recordedTransformAtRespawnTrack.position.x + " , " + recordedTransformAtRespawnTrack.position.y + " , " + recordedTransformAtRespawnTrack.position.z);
    }
}

public void CheckToRespawnCar()
{
    if (isRacing)
    {

        if (CrossPlatformInputManager.GetButtonDown("Jump"))
        {
            print("RESPAWN TRIGGERED BY PRESSING BUTTON");
            
            transform.position = recordedTransformAtRespawnTrack.position;
            transform.rotation = recordedTransformAtRespawnTrack.rotation;
          
            rb.velocity = recordedVelocityAtRespawnTrack;
            
        }

    }
}