- Home /
OnCollisionStay going one more time after i jump
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 ins$$anonymous$$d
if 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
//DETER$$anonymous$$INE IF ON GROUND
var rayHit : RaycastHit;
if (Physics.Raycast (transform.position, -Vector3.up, rayHit, 1.25))
{
grounded = true;
}else
{
grounded = false;
}
And 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.
oh cool thanks again, i thought you had to have the hit for some reason
Answer by iwaldrop · Dec 07, 2013 at 05:47 AM
Instead of using OnCollision handlers to determine if you're touching the ground you might consider using a raycast downwards.
Your answer
Follow this Question
Related Questions
Collision.point not working 1 Answer
Setting a delay before dashing. 1 Answer
Is it possible to increase the fixedDeltaTime only for a single object? 0 Answers
What variable type is this? 1 Answer