- Home /
Question by
JewishPriest · Sep 07, 2014 at 01:37 PM ·
movementmovement scriptjava
Object moving on its own
I am making a ball puzze game platformer where you gotta dodge things and move your ball to the end of the course to reach the next level. Anyways, my ball moves at a steady speed on its own. When you hit wither "d" or "a" it accelerates the ball but it never slows down unless it is opposed by the opposite key. Heres the code:
#pragma strict
var rotationSpeed = 100;
var jumpHeight = 8;
private var isFalling = false;
function Update ()
{
//Handle ball rotation
var rotation : float = Input.GetAxis ("Horizontal") * rotationSpeed;
rotation *= Time.deltaTime;
rigidbody.AddRelativeTorque (Vector3.back * rotation);
if (Input.GetKeyDown (KeyCode.W) && isFalling == false)
{
rigidbody.velocity.y = jumpHeight;
}
isFalling = true;
}
function OnCollisionStay ()
{
isFalling = false;
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613162505im_/https://answers.unity.com/themes/thub/images/avi.jpg)