Reset Rocket Position

Hey everyone,

I wanted to add a function to reset the rocket position, rotation, and stop its velocity when I press the ‘R’ button and figured it out! Feel free to use it.

Vector3 startingLocation;

void Start {
     startingLocation = transform.position;
}
void Update {
    ResetPosition();
}

private void ResetPosition() {   //reset Position on landing pad
        if (Input.GetKey(KeyCode.R)){
            transform.position = startingLocation;
            transform.rotation = Quaternion.identity;
            rigidBody.velocity = new Vector3(0,0,0);
        }
}

what is quaternion?

I believe Quaternion means “no rotation”

So that expression Quaternion.identity resets the object’s rotation as if you were setting
Transform > Rotation
x=0
y=0
z=0

Privacy & Terms