CollisionShape "on ground" - best practice for calculating

Hi all,

I’m trying to figure out if a CollisionShape is “on ground” i.e. colliding with another shape ‘under’ it. I have tried a few ways I can think of, but they all fell overly complicated and awkward.

Just wondering what was the best way to achieve this?


Just check if you get a collision event from that object each physics tick using the physics tick listener or do a ray test to see how far the floor is away.

Thanks for your (super fast) help yet again normen.

normen said:
check if you get a collision event from that object each physics tick

I'm not sure what you mean, I have setup my tick listener ok, I'm not sure how to 'check for a collision event'.... I tried using a collision listener to set a flag if there was a collision but the physics ticks are happening faster than the collision listener gets called.


Yep, I read through all the physics related documentation (several times) and have been sifting through the source, I came here for help because I can’t figure it out.

I’m still unsure on how to ‘check for a collision event’, I thought event listeners got called, I don’t know how to poll an event from my physics tick.

How can I check for a collision between two collision shapes in a physics tick (ie without using a Collision Listener). I know I can do collision checking between spatial and rays etc, but I can’t work out how to do a check with a CollisionShape e.g. shape.collideWith(shape) ?


The PhysicsCollisionEvent is delivered to the collision method you implement. Look at the test class to see it implemented.

I’m sorry but I’m just so lost…

I understand events, I know how the Collision Event Listener works, and how the PhysicsCollisionEvent is delivered. I also familiar with the tick system.

You suggested checking for a collision event during a physics tick, I don’t get how to access the PhysicsCollisionEvent generated during an unrelated event, during a tick ? During some ticks, there is not even a collision, so there would have been no collision event generated.

Just use variables? Pseudocode:

[java]boolean onGround=true;

private void onCollision(physicsEvent){





private void preTick(){



public void simpleUpdate(){






When I tried that, I found the physics ticks are occurring more frequently than the collision event is being broadcast. So while the “object is on the ground”, 2 to 4 physics ticks would occur between collision events.

Well then your object is really bouncing on the floor, just add a timer.

time += tpf;

if(time>maxTime && no_new_collision){



ok cool, I tried something similar but I used ticks not time (which I guess are pretty much the same … 1 tick = 1/60sec), it was a bit flukey but i guess it just needs some refinement.

Thanks a lot for all your help normen, I can now push forward knowing I’m on the correct path :slight_smile: Kinda sucks, I was doing all this anyway, but it just felt wrong.