Finding another easier way to detect whether a character can jump or not

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By tam0705
:warning: Old Version Published before Godot 3 was released.

I’m making a 2D game and using tilemap to make the environment easier to modify.

I have a rigidbody with a ball shape as a character. I want to make it jump everytime it collides with the surface of the tiles, so I tried to print what it collides with everytime it touches the surface.

The result was [TileMap:IDNumber]

Not only when it touches the surface, but the output also printed [TileMap:IDNumber] when the ball touches a wall with the same IDNumber!

So I made an area and put every collision shape on every surface to detect whether the player can jump or not, and it’s tiring and wasting time because my game environment is not thoroughly flat.

Can people tell me whether there are easier ways or not, because if I want to make other games where the player can jump I have to do this way.

Sorry for bad English. (Before I post this question I’ve tried to print what the player collided with but then it didn’t print anything -_-)

:bust_in_silhouette: Reply From: timoschwarzer

If you need your player to be a RigidBody2D, you can use a downward-facing RayCast2D and check if your body and the RayCast2D are colliding.
The cleaner way would be that you use a KinematicBody2D and calculate the floor angle using the collision normal. Unfortunately this involves writing all the physics stuff yourself, but you will have control over any movement your player will do.

I’m so sorry that I don’t reply until 4 days passed, I’m rather inactive in this Godot Forum.

I haven’t even heard there was a node named RayCast or RayCast2D, it seems I’ll check it out, thank you for answering :slight_smile:

tam0705 | 2017-06-06 03:21