- Home /
Rigidbody.AddForce and incorrect rotation
I'm using a sphere for a player and using rigidbody.AddForce to move it around, and the rotation is generated by friction with the ground. Unfortunately, its rotation isn't matching its movement, and at higher speeds it seems to be rotating at about the third of the speed it should be.
This is the base of my movement code:
float speed = 24;
void FixedUpdate()
{
Vector3 camF = new Vector3(transform.position.x - camera.transform.position.x, 0, transform.position.z - camera.transform.position.z).normalized;
Vector3 camR = camera.transform.TransformDirection(Vector3.right);
rigidbody.AddForce(camF * Input.GetAxis("Vertical") * speed);
rigidbody.AddForce(camR * Input.GetAxis("Horizontal") * speed);
}
The player has a mass and drag of 1. Is there a better way to do this?
Answer by dhfijhgky · Dec 10, 2013 at 06:53 AM
I solved it by going into Edit -> Project Settings -> Physics and changing the maximum angular velocity.
Answer by GameVortex · Dec 07, 2013 at 09:09 AM
Drag is not friction to the ground, it is the resistance the "air" applies. Unity does not apply any specific friction normally. To have proper friction between two objects you have to use Physics Materials. Add a Physics Material to each object and specify their dynamic and static friction. Manual: Physics Material.
I tried increasing friction and decreasing drag, but it didn't change anything.
I tried AddTorque, which simulated better movement. Unfortunately movement speed seems to be limited by roughly the same rotational speed I had with AddForce, like I'm reaching a cap for how fast I can rotate.