0 votes

I've a Raycast2d to check collisions and and I need to get the object that it has collided with to know the size and position of its collisionshape, but raycast.is_colliding() only gets the object (node), and if I don't know the collisionShape node name i can't get it.

The Scene:

Player (KinematicBody2D)

Stone (RigidBody2D)
   CollisionShape2D (CollisionShape2D)

AnotherObstacle (Area2D)
   CollisionShape2D (CollisionShape2D)


if Player.RayCastTop.IsColliding():
    var collisionShape2d = getCollisionShape2D (Player.RayCastTop.GetCollider())
    collisionShape.Height = ??
    collisionShape.Width = ??

If there any way to get the CollisionShape2D of an object returned by raycast.get_collider() ?

asked Jun 6 in Engine by Ditoga (24 points)

1 Answer

0 votes

Nothing special about it. Assuming the CollisionShape2D is a direct child of the node the Raycast2D is colliding with, it would be as simple as this:

var collider = raycast.get_collider()
if collider:
    var collision_shape = collider.get_node("CollisionShape2D")
    # ...

If it's not a direct child, than you need to adapt the NodePath accordingly.

answered Jun 12 by njamster (8,990 points)
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.