Game Development Reference
In-Depth Information
//Set up the last y-axis position of our character
f_lastY = transform.position.y;
b_isJumping = false;
3. Next, we go to the public function Update () funcion and add some code as
follows (the highlighted part is our new code):
//If our character isn't jumping
if (!b_isJumping) {
if (Input.GetButton("Horizontal")) {
//Walking
in_direction = Input.GetAxis("Horizontal") < 0 ? -1 : 1;
rigidbody.velocity = new Vector3((in_direction*f_speed),
rigidbody.velocity.y, 0);
loopSprites[0].resetFrame();
loopSprites[1].updateAnimation(in_direction, renderer.
material);
} else {
loopSprites[1].resetFrame();
loopSprites[0].updateAnimation(in_direction, renderer.
material);
}
if (Input.GetButton("Jump")) { //Jump
b_isJumping = true;
//Then make it Jump
loopSprites[0].resetFrame();
loopSprites[1].resetFrame();
rigidbody.velocity = new Vector3(rigidbody.velocity.x,
-Physics.gravity.y, 0);
}
} else {
//update animation while it Jump
jumpSprite.updateJumpAnimation(in_direction, rigidbody.
velocity.y, renderer.material);
}
So, we basically add the statement to check if our character is jumping or not.
4. Next, we add the highlighted code in the LateUpdate() funcion, in which we
already had our camera update posiion:
public function LateUpdate() : void {
//Checking Jumping by using Raycast
var hit : RaycastHit;
var v3_hit : Vector3 = transform.TransformDirection (-Vector3.
up) * (f_height * 0.5);
var v3_right : Vector3 = new Vector3(transform.position.x +
(collider.bounds.size.x*0.45), transform.position.y, transform.
position.z);
 
Search WWH ::




Custom Search