- Home /
Question by
Balsamic_Vinegar · May 04, 2012 at 08:15 AM ·
rotationmovementcharactersmoothrigidbodies
Undesirable character flipping
Hi all,
I've written a fairly simple script to move a character to a point smoothly; the script also rotates the character smoothly to face the rigidbody velocity. However, I have encountered an issue with the character flipping over rapidly on in z axis, especially at points where the character supposed to be upside down. The script seems to force it's local y to match the world y.
Of course this could be due to how I'm rotating the character, but I would like to know if anybody has any superior methods to accomplish this smooth rotation.
My script:
public bool _active;
public Transform aim;
public float maximumSpeed, acceleration, agility;
private float currentSpeed;
private GameObject character;
void FixedUpdate() {
if(_active) {
currentSpeed = Mathf.Lerp(currentSpeed, maximumSpeed, Time.deltaTime);
Vector3 velocity = (aim.position - character.transform.position).normalized * currentSpeed;
character.rigidbody.velocity = Vector3.Slerp(character.rigidbody.velocity, velocity, Time.fixedDeltaTime * agility);
character.transform.forward = Vector3.Lerp(character.transform.forward, character.rigidbody.velocity, Time.fixedDeltaTime * agility);
}
}
Comment