- Home /
Ground Checker
I need a ground checker for my jump mechanic but I have no idea how to do so and I have searched online and it didnt help :c
A code in java would be helpful
Its not a clear explanation of your prroblem at all. We dont know if you are making a 2D or 3D game. We dont know that you are using character controller, rigidbody or just translating the transform.
var speed : float = 1;
function FixedUpdate () { if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.D)) { transform.position += Vector2.right * Time.deltaTime;
Answer by Scribe · Aug 08, 2014 at 06:58 PM
Perhaps something like this would work:
var grounded : boolean = false;
function OnCollisionStay2D(collisionInfo : Collision2D){
for(var contact : ContactPoint2D in collisionInfo.contacts){
if(contact.normal.y >= 0.9){
grounded = true;
}
}
}
function OnCollisionExit2D(){
grounded = false;
}
and then only allow jumping if 'grounded' is true!
Scribe
whats the correct term for doing the if 'grounded' is true?
if(grounded){
//do stuff
}
for anyone else trying to figure that out!
Thanks for marking as answered vultt3rim :)
Answer by ThyagoBraw · Aug 08, 2014 at 01:39 PM
var speed :float = 5.0;
function FixedUpdate () {
if (Input.GetKey(KeyCode.Espace)) { transform.Translate(0,speed * Time.deltatime,0);
}
}
Your answer
Follow this Question
Related Questions
How do I get my "dashing" animation to work? 1 Answer
CharacterMotor problem (Js) 1 Answer
AddForce to sphere 1 Answer