So, I have a jumping code that uses raycasts:
function Update ()
{
var direction = transform.TransformDirection(Vector3.down);
var hit : RaycastHit;
var localOffset = transform.position;
if (Physics.Raycast (localOffset, direction, hit, 1) && Input.GetKey("up"))
{
rigidbody.AddForce (Vector3.up*200);
}
}
My problem with this code is that it is inconsistent. Sometimes it barely hops, other times it explodes off the screen. Is there a way to better this code (or an entirely different method?)that I could use to make more consistent jumping?