Walking not frame rate independent

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;
}

Fixed it

Well… how?

It’s good form to share so that future users searching for similar answers can find it.

A quick note on the above, if using a Rigidbody it’s best practice to use FixedUpdate() rather than Update(), because it’s called in step with the physics system where Update() and LateUpdate() are not. With the above, for instance, you’re calling AddRelativeForce(…) every frame instead of every physics tick, and with a variable frame rate that means that some physics ticks will get more force added than others.