Question by
$$anonymous$$ · Jul 11, 2016 at 05:33 PM ·
jumpjumpingjumping object
How to make my ball jump?
I am using the roll-a-ball script, and the tutorial never showed how to make the jump. I would like to make a similar game, and have the ball jump would be very helpful. Thanks in advance!
code so far: (roll a ball)
} void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
rb.AddForce (movement * speed);
}
}
Comment
Sorry, for whatever reason, the code looks a little funky, it normally compiles and runs fine.
Answer by jhunglow · Jul 27, 2016 at 03:29 AM
public float jumpHeight;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void FixedUpdate()
{
if(Input.GetKeyDown(KeyCode.Space)
{
rb.AddForce(Vector3.up * jumpHeight);
}
}
where do we add this? above the other coding or in which certain area