- Home /
How do I check when a rigidbody is colliding with the floor?
:D
Im trying to make a rigidbody 'Jump' but only when he is on the floor. obviously you cant jump when you are alredy jumping ^.^. thats what exactly do my rigidboy! it "jump" when its alredy "jumping".
Any idea? :P
Thanks!
if(Input.GetButtonDown("Jump"))
{
rigidbody.velocity = Vector3(0,JumpHeight,0);
renderer.material.SetColor ("_Color", Color.red);
}
Answer by Metalkat.du · Feb 20, 2011 at 06:57 PM
May be checking if is not touching your "thing" tagged ass floor?... Send me a msg if it works... i didnt test it, and for bugs or that o:... Salute.
edit: try with OnTriggerExit and with OnTriggerEnter... dont know what of them may work better...
// new var Jumping var Jumped = false;
// your code if(Input.GetButtonDown("Jump") && !Jumped) { rigidbody.velocity = Vector3(0,JumpHeight,0); renderer.material.SetColor ("_Color", Color.red); Jumped = true; }
function OnTriggerExit( touching : Collider ) { if(touching.gameObject.tag == "Floor") { Jumped = false; } }
How would I do this, if there are other ways for the rigidbody to become not touching the floor, for example falling off of something?
Answer by Joshua · Feb 21, 2011 at 01:44 AM
function Update() { var controller : CharacterController = GetComponent(CharacterController); if (controller.isGrounded) {
Much easier and works fine. Assumes you have the Charactercontroller script on your character of course.
Thanks for the answer! was useful too but im not using Character Controller, im using my own script! THanks!