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;
}
}
}