0 votes

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 -_-)

asked Jun 1, 2017 in Engine by tam0705 (59 points)

1 Answer

0 votes

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.

answered Jun 1, 2017 by timoschwarzer (700 points)

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 :)

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.