- Home /
How do I reset my object rotation when it collides and spins around
All of these solutions that I google do NOT work
You may have to be a bit more descriptive of what exactly you are trying to achieve. If you want to simply set the rotation of an object to the default rotation, use transform.rotation = Quaterion.identity
. If you spawned it in with an orientation that is not the default orientation and you want to set it to that, you could do something like
private Quaterion startingRotation;
void Awake(){
startingRotation = transform.rotation;
}
//Somewhere else in the same script, when you want to reset the rotation
transform.rotation = startingRotation;
Answer by logicandchaos · Jan 30, 2020 at 12:33 AM
Well a simple way would be to just get the value of the rotation before the collision and then set it to that after the collision.. you could do this a few ways
Quaternion rotation;
OnCollisionEnter(){
rotation=transform.rotation;
}
OnCollsionExit(){
transform.rotation=rotation;
}
Or if you are using OnCollision()
Quaterion rotation;
OnCollision(){
rotation=transform.rotation;
Invoke("ResetRotation",.5f);
}
public void ResetRotation(){
transform.rotation=rotation;
}
You will have to fill in the collision parameters correctly.
you might also have to set velocity and rotational velocity to zero. also if you don't want the gameObject to rotate at all you can limit that in the editor.