- Home /
Question by
Velketor · Jul 24, 2013 at 01:50 PM ·
jumpmovement scriptlag
Laggy Movement
This script is working but for some reason when I move left or right I lag horrifically. As soon as I don't move left or right, the lag is gone. The jump function works fine, causes no lag and it's in the same script. What could be causing this?
function Update() {
MoveHero();
JumpHero();
}
function MoveHero() {
if (Mathf.Abs(Input.GetAxis("Horizontal")) > 0.2) {
if (Input.GetAxis("Horizontal") > 0.02) transform.eulerAngles.y = -90;
else if (Input.GetAxis("Horizontal") < -0.02) transform.eulerAngles.y = 90;
transform.Translate(Vector3.forward * Mathf.Abs(Input.GetAxis("Horizontal")) * Time.deltaTime * 40);
}
}
private var nextJump : float;
function JumpHero () {
if (Input.GetButton("jump") && nextJump < Time.time) {
rigidbody.AddForce(Vector3.up * 500000);
nextJump = Time.time + 1;
yield WaitForSeconds(1);
}
}
Comment