- Home /
Unitysteer - Rigidbody with gravity stops steering
When I have rigidbody with gravity enabled on the object being steered. after about a moment of movement, it comes to a stop. I disable gravity, and it works fine. If I change the mass in rigidbody, it goes further. Is there any way to remove mass from the movement calculation?
Answer by Ricardo · Nov 17, 2010 at 11:27 AM
Hello Jon,
As denewbie points out, if the character has a rigidbody, then AutonomousVehicle's behavior will be affected by physics.
You have several options:
- Reduce the rigidbody's mass.
- Increase the force being applied to the object.
- Alter AutonomousVehicle.ApplySteeringForce and not take Mass into account.
You could even create a simpler vehicle if the considerations taken by AutonomousVehicle are too elaborate for the effect you're trying to achieve.
Answer by denewbie · Nov 17, 2010 at 11:21 AM
The reason why it stops is because of friction with the ground. The object looses energy due to that friction and slows down until it comes to a complete stop. Reducing the mass will only delay the stop time. What I ll suggest is to
1) add a force to the object and change it based on the rigid body's velocity
So you could try something like this:
(This is in C#)
float maxVelocity = 10f; float myForceSize = 0f public float variator = 0.1; public Vector3 initVel = Vector3.forward * 10f; // Set the initial velocity of the object
funtion Start(){ rigidbody.velocity = initVel; }
function FixedUpdate () { if (maxVelocity < rigidbody.velocity.magnitude ) // When speed is too fast myForceSize -= variator; else if (maxVelocity > rigidbody.velocity.magnitude) // When speed is too slow myForceSize += variator; else // When speed is just nice myForceSize = 0f;
rigidbody.AddForce (Vector3.up * myForceSize);
}
2) Directly change to velocity per fixed update (Not recommended tough)
rigidbody.velocity = myVel; // Where myVel is a Vector3
3) You can try moving the object via Translation : myBody.transform.Translate(Vector3.forward * mySpeed);