How to use Raycast

I’m not understanding how Raycasts work in Playcanvas, so here I drop a very simple question.
I have an entity A and an entity B. I want to throw a ray from entity A position to entity B position. If the ray collides with entity B, the function returns true. If something blocks me in between, return false.

How I can do that? Can you bring me a simple piece of code? Thanks!

Hi @PolVegaTPM,

You can use rigid body components on your entities and from there you can use the raycast method to do that. Check the following examples on that:

1 Like

Nice drawing :slight_smile:
You can also check this raycast example:

1 Like

You can also use tags on the entities to query against to know if the ray is hitting a wall or another player.