How do I make onCollisionStay work?
So I'm trying to build a 3D platformer type game. It's my first game, so it's simple, and the main character is a sphere. What I'm trying to do is only allow the sphere to jump when it's touching the ground. Here is the code I have so far:
//MU is the variable which holds the upwards force
//speedjump is a public variable which is a multiplier for the amount of jump
//rb is the rigidbody for my sphere/player
void onCollisionStay() {
MU = Input.GetAxis("Fire1")*speedjump;
rb.AddForce(0.0f, MU, 0.0f);
}
So the onCollisionStay() should detect when I am touching the floor, and if I am pressing fire1, it should jump, right? But, for some reason, it isn't jumping at all. The code above works in FixedUpdate, but then you can just fly, since it doesn't check that you are touching the ground. Any help with this problem?
Answer by hexagonius · Jan 17, 2016 at 08:56 PM
It's OnCollisionStay, not onCollisionStay. Be careful with the spelling of Unity's callbacks
Thank you! I am just used to Java where the first letter is usually lowercase. I'll keep this in $$anonymous$$d for the future.
Your answer
Follow this Question
Related Questions
How to Ignore Collisions Between a Layer and a LayerMask? 1 Answer
Recreating 'skin width' functionality on a rigidbody? 0 Answers
Rigidbody randomly going through collider 1 Answer
Why is my trigger collider acting like a normal collider? 1 Answer
Physics.OverlapSphere not detecting collision! Collision help. 1 Answer