CollisionHandlerFloor and Floor detection

Hi there,

I just found the CollisionHandlerFloor in the manual. Is there any way to tell when the character is on the floor when using it to enable/disable the jump(button)? Or is this not intended for jumping but walking only?

Greetings

CollisionHandlerFloor inherits from CollisionHandlerEvent, so you can use event handlers to detect such a thing.

However, also check out CollisionHandlerGravity, which is like Floor but designed for jumping. It has an isOnGround() method.

1 Like

I would recommend refraining from making decisions by default. Since they were implemented long ago and have some drawbacks. It is better to use ray and mathematical calculations when growing from ray to surface.

I did. Worked fine for the floor. But I have multiple players and wanted to make it possible to jump on other players.
So I created a collisionbox on top of the player. But my code:

if re.match(“Player_\d_floor”,entries[entrynumber].getIntoNode().getName()):
standonPlayer=int(re.search("\d",crashedInto).group()[0])
if crashedInto == “track” or ( standonPlayer not in [0,self.number] ):
self.floor_distance = entries[entrynumber].getSurfacePoint(self.own_node).get_z()
self.floor_z=entries[entrynumber].getSurfacePoint(render).get_z()
#debug
#if self.floor_distance != -3:
#for later: prints -3.0
#print(“self.floor_distance”+str(self.floor_distance))
if self.floor_distance >= -3:
#if self.jumping:
#print(“landing on floor”)
#print(“on the floor”)
if self.floor_distance >-3:
self.land()
elif self.floor_distance <-3:
#fall if the ground is too far away
self.jumping=True

Has to be wrong somehow because when I land on another player, both fly into the air and do not stand on each other. I changed something. But as of right now the lower player get’s beamed up opun the player which is jumping on the other this should not be and when the lower player goes away, the player standing on top does not fall down and stays in the air until he jumps himself. Still have to find the cause for the “beambug” guess the other one is easier to fix.

I thought I could get rid of this by letting another collisionHandler handle it.

Most likely, you need to sort finding the near surface, before comparing the distance. And from the near surface to make calculations.

1 Like

At first thought this should solve it. But looking at my source again I do a
self.floor_handler.sort_entries()
first and only look atthe first(array-entry 0) of the collisionhandler which should be the nearest surface. So this became weirder.

Lol, I added a loop and now BOTH problems where solved by this loop:
crashHandled = False
while not crashHandled:
with crashHandled being set to true when a “legit” floor is found. A not legit floor being the own “standing-on-box” or anything not recognized and the index of the entries being counted up when the floor is not legit.