x


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);
 }
more ▼

asked Feb 20 '11 at 06:15 PM

SosaZero gravatar image

SosaZero
5 2 2 7

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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;
    }
}

more ▼

answered Feb 20 '11 at 06:57 PM

Metalkat gravatar image

Metalkat
26 3

THanks it worked perfectly! :D

Feb 23 '11 at 12:21 AM SosaZero

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?

Feb 15 at 09:52 PM varesa
(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Feb 21 '11 at 01:44 AM

Joshua gravatar image

Joshua
6.4k 19 25 71

Thanks for the answer! was useful too but im not using Character Controller, im using my own script! THanks!

Feb 23 '11 at 12:22 AM SosaZero
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3744
x1797
x336
x169
x117

asked: Feb 20 '11 at 06:15 PM

Seen: 2548 times

Last Updated: Feb 15 at 09:52 PM