- Home /
How can I check for a collision before or during FixedUpdate()?
I am making a physics-based marble game and am having trouble getting the marble to jump properly. Right now, I think that it jumps twice when I press the jump button. Here is the code for jumping.
function FixedUpdate () {
if (Input.GetButton("Jump") && canJump) {
rigidbody.AddForce(Vector3.up * jumpForce,ForceMode.VelocityChange);
canJump = false;
}
}
function OnCollisionStay () {
canJump = true;
}
function OnCollisionExit () {
canJump = false;
}
I think that the first time the marble jumps, it is still in contact with the floor, so OnCollisionStay reverts canJump to true and lets it jump a second time. Because of this issue, I want the code to check for collisions before the if statement. How can this be done?
Answer by markedagain · Jul 14, 2013 at 10:26 PM
a quick dirty solution would be to put a timmer of some sorts to not allow jumping for 500 ms, or you can set a isJumping bool of some sort and then as long as its true, keep checking the direction you are headed if its down ie falling set it to false
Your answer
Follow this Question
Related Questions
how to instantiate an object every second? 2 Answers
What's FixedUpdate 2 Answers
Effective way to change var after buttondown 1 Answer
OnCollisionStay & FixedUpdate 1 Answer