#Issue with ray casting colliding with objects behind other objects

28 messages · Page 1 of 1 (latest)

primal shore
#

I am trying to make a basic FPS game for a game jam that I am preparing for, and I'm currently implementing the ability to shoot. My method of doing it is having a ray from the characters line of sight shoot off very far into the distance (image 1). When I attempt to print what the ray collides with, it works, unless there is something behind the enemy I'm trying to have it collide with.
When I click on the enemy when there is nothing but sky behind it, it prints that I am hitting the enemy (image 2, look at console output).

If I click when a static body is behind the enemy, it prints the StaticBody3D instead of the enemy. (image 3, look at console output)

Why wouldn't get_collider() be printing the enemy, but the thing behind it?

Let me know if this is too ambiguous of a question, I can add more details.

sly pivot
#

Hello @primal shore ,
In the main toolbar on top, you have a debug menu. In it you can make visible the collisions. Does it help ?

primal shore
#

It did not help

#

get collider is returning the furtherst item it collides with

#

it seems

sly pivot
#

You can see the collider when you run the game. Can you made new screenshots with this option please ?

primal shore
#

it detects the enemy

#

get_collider finds the enemy if its the last thing the ray collides with

sly pivot
#

Where is the static body on your screenshot ?

primal shore
#

The floor and the platform to the right are static bodies

#

I flipped it vertical for testing

#

If the enemy is the last thing it collides with, it detects it

sly pivot
#

So you clic on enemy, next on the vertical platform and it continue to return the enemy ?

primal shore
#

If I stand behind wall and click towards enemy, it prints enemy, if I stand behind enemt and click towards wall it prints wall

#

The raycast prints the object that is furthest away from the origin instead of the first thing it hits

sly pivot
#

Do you modify some options in raycast node ?

primal shore
#

I dont think I did

#

well I did for masks

#

and excluding the parent

sly pivot
#

Hum 🤔... Maybe the mask... I do not have other idea sorry 😅

primal shore
#

The main character (me) is in layer 1, the wall is in layer 2, the enemy is in layer 3,

#

The collision masks for the ray are 2 and 3, which is walls and enemy

#

so im out of ideas

#

Discovered a fiox

#

I just flipped my vision ray 180 degrees in the y axis so the tip of it started in the player instead of the beginning it of

#

Marking it as solved