Hey,
Im trying to work out a method of detecting when an object leaves the ground and then returns so I can trigger something.
I did try a nested if statement
if (object not in contact with floor)
{
if (object in contact with floor)
{
Do x
}
}
But that didn’t work. anyone have any ideas?
if they leave the ground based on some input, I would set a variable “onGround = false” maybe
when they hit the ground, you’d have a trigger/collision/raycast (which, btw, you could check for only when onGround is false). When that part occurs (ie: finding the ground again), set onGround to true and do your action.
If the object can fall in other unpredictable ways, that’s different. More follow up, depending on your situation. ![]()
Ah that makes sense, thanks ![]()
Im working on a device which will allow people to walk around in VR. The device is attached to the players shoes, so they dont have any unpredictable movement ![]()
well, i mean like if they could fall off a ledge?
Then you’d need some way of determining when they’re off of the ground.
Otherwise, if no such situation exists, but they can jump… I’d go with the onGround variable to false when they jump and other options I mentioned in my first post.
Hope that helps.
Awesome, ill give it a go, thanks ![]()
Cool
Quick question, I’ve made the ground a trigger, but would I attach the on trigger event to the object that will trigger it, or to the floor? im a bit confused as to where it should go
You can attach to either, just check that the trigger is the opposite & you’re not on the ground when landing, I’d say. You will require a Rigidbody, as well, to complete the process. It can be kinematic or non-kinematic.
Cool, that makes sense, thanks ![]()
I should semi-correct myself here about the trigger portion. It was an oversight on my part, if you’re using gravity**. If the person can fall through the ground, switch to OnCollisionEnter, (using the same circumstances, ie: only if not onGround). or I think you could have a second collider on the ground/person (so, one that is a trigger, and one that isn’t).
Reason is that if you can fall and 1 object is a trigger only, it will trigger events, however objects can pass straight through . lol
If you aren’t using gravity/physics and have some hand-made jump (ie: without physics), I’m pretty sure just the trigger should work.
Hopefully I didn’t steer you badly ![]()
Nope you steered me pretty good, Sorry been working on other things the past few days. The collision works beautifully, thanks
Do you have any idea how I could move an object forward a small amount each time the collision happens?
Little out of touch, since a few days have passed, but you can move forward a little in your OnCollisionEnter if you want to.