So I have a movement script for a rigidbody. I use Time.deltaTime for everything but it definitely isn’t framerate independent. Lower framerates make you move faster, and higher framerates make you move slower. Check out my code.
#pragma strict
var MovementSpeed = 7000;
private var MovementVer : int;
private var MovementHor : int;
private var distGround : float;
var MaxSpeed : float;
var jumpSpeed : float;
function Start(){
distGround = collider.bounds.extents.y;
}
function IsGrounded() : boolean {
return Physics.Raycast(transform.position, -Vector3.up, distGround + 0.1);
}
function Update() {
//setting up the movement variables
MovementVer = Input.GetAxis("Vertical") * MovementSpeed * Time.deltaTime;
MovementHor = Input.GetAxis("Horizontal") * MovementSpeed * Time.deltaTime;
//Stops the character from sliding around when you aren't moving
if(Input.GetAxis("Vertical") != 0 || Input.GetAxis("Horizontal") != 0) {
rigidbody.drag = 1;
}
else{
rigidbody.drag = 10;
}
if(Input.GetAxis("Jump") && IsGrounded()){
rigidbody.drag = 0;
rigidbody.velocity.y = jumpSpeed;
}
if(IsGrounded() == false){
rigidbody.drag = 0;
}
if (IsGrounded() == false){
MovementSpeed = 2;
}
if (IsGrounded() == true){
MovementSpeed = 7000;
}
}
function FixedUpdate () {
rigidbody.AddRelativeForce(Vector3(MovementHor, 0, MovementVer));
}