Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Kentaro |
Good day,
i have a problem with the detection of collisions in a 2D top down project.
The player is a KinematicBody2d with the movement via move_and_collide. In the map the player is on his own PB2D layer and mask. The tiles in the tilemap have all some CP2D and the tilemap is on its own layer and mask.
The collision detection works if both player and tilemap are on the same layer but then the player cant “go through / go over” the tile.
I want is to detect if the player is moving over the tile with the name or number x and then cut his move speed in half.
Is there away to make this possible or do i have to rethink anything?
The code can be found GitHub - Fedena22/NGP: Next game Project
Thanks for your help.
You can get Player position in Tile space with function in TIleMap class: world_to_map, e.g.: var playerTilePosition = TileMap.world_to_map(Player.position).
Then you need to check if playerTilePosition has same index as a tile that should slow down Player, e.g.:
if TileMap.get_cellv(PlayerTilePosition) == “YourSlowDownTIleIndex”:
playerVelocity = playerVelocity/2
pospathos | 2018-11-10 00:20
Becouse you are using KinematicBody2D, on tiles that should slow down Player you should use Area2d, and then check with: body_entered().
pospathos | 2018-11-10 00:26