im using OnCollisionStay to check if the player touched the ground, and i want to make it so the player can grind if they jumped, the problem is it goes into OnCollisionStay and disables the variable tracking that you jumped up
it’s hard to explain so heres some code i used to mess with it:
function FixedUpdate ()
{
// Jump
if (Input.GetMouseButtonDown(0))
{
rigidbody.velocity = Vector3(velocity.x, CalculateJumpVerticalSpeed(), velocity.z);
justJumped = true;
}
}
function OnCollisionStay () {
justJumped = false;
}
function OnTriggerStay (hit : Collider) {
//GRIND
if(hit.tag == "rail")
{
//so player jumped to grind
if(justJumped)
{
//grind code
}
}
}
if i debug.log where i turn on/off justJumped, OnCollisionStay runs one more time before i am completely in the air
is this because of the order that these functions go? I dont know how to fix this…
thanks
oh that's a good idea, then it would prolly be more reliable too maybe i will just do that instead
– TimBorquezif you want you can convert your comment to an answer as it totally solved my problems haha, thanks i have this on the top of my update before anything else and everything is workin fine //DETERMINE IF ON GROUND var rayHit : RaycastHit; if (Physics.Raycast (transform.position, -Vector3.up, rayHit, 1.25)) { grounded = true; }else { grounded = false; }
– TimBorquezDone. Glad it helped.
– iwaldropAnd just FYI, since Raycast returns a bool, that can be done in one line, and unless you need the hit info it's faster not to pass it in.
– iwaldropoh cool thanks again, i thought you had to have the hit for some reason
– TimBorquez