Hi,
I’m developing a simple rigidbody character controller but I’ve found that with my current jump mechanic when the character becomes grounded I can’t always jump within the first 0.2seconds of becoming grounded… I can’t work out whether this is caused by the grounding check function being slow to return true, or something else.
Can anyone suggest a better way of handling grounding and jumping so that it responds the second the player sees the character hit the ground and responds that fast too.
My current mechanic :
function FixedUpdate (){
if (grounded){
// Jump
if (canJump && Input.GetKeyDown("x")){
rigidbody.velocity = Vector3(velocity.x, CalculateJumpVerticalSpeed(), velocity.z);
}
}
grounded = false;
}
function OnCollisionStay (hit : Collision){
if(hit.contacts.Length > 0) {
var contactPoints = hit.contacts;
if((Vector3.Dot(contactPoints[0].normal, Vector3.up)) > 0.5){ //Check for floor and upwards
grounded = true;
}
}
}
function CalculateJumpVerticalSpeed (){
// From the jump height and gravity we deduce the upwards speed
// for the character to reach at the apex.
return Mathf.Sqrt(2 * jumpHeight * gravity);
}
Note: I’ve omitted the parts of the script that deal with gravity and movement to make it clear what the focus of my question it.
Cheers - Caius
This is not an answer. This should be a comment.
– DESTRUKTORR