- Home /
Question by
Lunas Lama · Sep 13, 2014 at 08:41 PM ·
raycastterrainjumping
Can't jump on terrain at specific angle
I'm not sure how to explain it. Well.. My character (a sphere) is moving on a terrain and is be able to jump. I'm using a raycast to let the character know, when he can jump. But it's not working right. If there is just a little hill on the terrain, where the sphere can walk up, it won't jump there. Only if the terrain is flatten.
Here's the code I'm using for the jumping part:
public var jumpForce : float;
public var hit : RaycastHit;
public var distanceToGround;
var IsKeyDown = false;
function Update () {
if (Physics.Raycast (transform.position, -Vector3.up, hit)) {
distanceToGround = hit.distance;
}
if (Input.GetKeyDown(KeyCode.Space) && (hit.distance <= .5)){
IsKeyDown = true;
}else{
IsKeyDown = false;
}
}
function FixedUpdate() {
if (IsKeyDown == true){
rigidbody.AddForce(Vector3.up * jumpForce);
}
}
Any ideas how to solve this?
Comment