Hello game developers! This is my first time using the unity forums so forgive me if i’m not posting this in the exact place it should be. I’m having a problem with the player movement. If i’m have vsync on It locks it at 60 FPS and it’s fine. If i have it off, it makes the movement go SUPER fast. I have tried to fix it by using Time.deltatime but couldn’t. If anybody has any suggestions on how I should fix it, please tell me. Here is my script.
var WalkAcceleration : float = 5;
var CameraObject : GameObject;
var maxWalkSpeed : float = 5;
@HideInInspector
var horizontalMovemeant : Vector2;
var jumpVelocity : float = 20;
var maxSlope : float = 45;
@HideInInspector
var grounded : boolean = false;
function Update()
{
horizontalMovemeant = Vector2(rigidbody.velocity.x, rigidbody.velocity.z);
if (horizontalMovemeant.magnitude > maxWalkSpeed)
{
horizontalMovemeant = horizontalMovemeant.normalized;
horizontalMovemeant *= maxWalkSpeed;
}
rigidbody.velocity.x = horizontalMovemeant.x;
rigidbody.velocity.z = horizontalMovemeant.y;
transform.rotation = Quaternion.Euler(0, CameraObject.GetComponent(MouseLookScript).yCurrentRotation, 0);
rigidbody.AddRelativeForce(Input.GetAxis("Horizontal") * WalkAcceleration, 0, Input.GetAxis("Vertical") * WalkAcceleration);
if (Input.GetButtonDown("Jump") grounded == true)
rigidbody.AddForce(0, jumpVelocity, 0);
}
function OnCollisionStay(collision : Collision)
{
for (var contact : ContactPoint in collision.contacts)
{
if (Vector3.Angle(contact.normal, Vector3.up) < maxSlope)
grounded = true;
}
}
function OnCollisionExit()
{
grounded = false;
}