- Home /
Game running at different speeds on different quality levels.
So I got a strange problem. My game is running at different speeds on different quality levels. It does this even though I'm using the AddForce functions of unitys Physics engine to move my characters. Here's the code I use for one type of enemy:
direction = player.transform.position - transform.position;
angle = Mathf.Atan2(direction.x, direction.z) * Mathf.Rad2Deg;
transform.rotation = Quaternion.Euler(new Vector3(0,angle, 0));
rigidbody.AddForce(direction);
if (Mathf.Abs(rigidbody.velocity.x) > velocityCap)
{
rigidbody.velocity = new Vector3(velocityCap * Mathf.Sign(rigidbody.velocity.x), 0, rigidbody.velocity.z);
}
if (Mathf.Abs(rigidbody.velocity.z) > velocityCap)
{
rigidbody.velocity = new Vector3(rigidbody.velocity.x, 0, velocityCap * Mathf.Sign(rigidbody.velocity.z));
}
I can't find the source of this problem. Does it have to do with my velocity capping? I would appreciate all help I can get. Thanks!
Is this piece of code running inside the Update function? Update is called depending on the frame rate. Try to use FixedUpdate.
or use
rigidbody.AddForce(direction * Time.deltaTime);
ins$$anonymous$$d, Time.deltaTime is the time it took the current frame to load. bigger the time, bigger the force. but I'd follow @Bruno 's suggestion because of simplicity.
Answer by Klarax · Jan 05, 2015 at 02:03 PM
As previous have mentioned.
Use
FixedUpdate
and
rigidbody.AddForce(direction * Time.fixedDeltaTime);
assu$$anonymous$$g that Time.fixedDeltaTime is basically a constant you could go without it