- Home /
Question by
Jason Hamilton · Apr 18, 2011 at 03:17 AM ·
playercharactercontrollergravityjump
Gravity and Jumping for a Character Controller
Hey, I was trying to work out how to add jumping and I couldn't get it to work. :/
These are the vars at the top of my script:
private var moveDirection : Vector3 = Vector3.zero;
var JumpSpeed = 8.0;
var gravity = 20.0;
and this is in the function:
//Apply gravity
moveDirection.y -= gravity * Time.deltaTime;
//Jump
if(Input.GetButtonDown("Jump"))
{
moveDirection.y = JumpSpeed;
}
Is this the right way to go about this? is there a better way? Should the player have different components?
Comment
Answer by duclaw · Jun 13, 2013 at 10:38 AM
you can go to this link to learn jumping and other movements http://cgcookie.com/unity/2011/11/30/robot-series-part-01-movement/