Godot Version
4.4.1-stable
Question
I often found myself in the pickle that I’m creating a node with a detection area
and then when I need to move it and bounce it around I have to jump through hoops only to realize in the end that it won’t work because the
TileMapLayer
doesn’t give the coordinates of the Tile
at the collision.
func on_body_entered_wall_detection(body: Node2D):
if body is TileMapLayer:
var space_state = get_world_2d().direct_space_state
var query = PhysicsRayQueryParameters2D.create(
global_position,
(body.global_position - global_position),
$WallDetection.collision_mask
)
var intersect_result = space_state.intersect_ray(query)
var collision_normal = intersect_result.normal as Vector2
direction = direction.bounce(collision_normal)
Even when other Area2D
s collide, I’m unable to make them bounce. Is it easier using a PhysicsBody
like RigidBody2D
? Do I have to keep something in mind?
The current game is a top down game that doesn’t really use any physics (apart from the player that’s sliding along walls or so on).
Thanks a ton for your thoughts!