Raycast 3d and collision layers

Godot Version

4.2.2

Question

Hello, I am learning Godot and I am messing around with 3d navigation with point and click movement, I am stuck on how to make so the raycast ignores certain collision layers I managed to get it to ignore the player character with exclude = [self] but I want it to also ignore things like trees and rocks that I have set on layer 4. I can’t make any sense of the documentation of it.

here is my raycast portion of the code

func ShootRay():
var mousePos = get\_viewport().get\_mouse\_position()
var rayLength = 2000
var from = cam.project\_ray\_origin(mousePos)
var to = from + cam.project\_ray\_normal(mousePos) \* rayLength
var space = get\_world\_3d().direct\_space\_state
var rayQuery = PhysicsRayQueryParameters3D.new()
rayQuery.exclude = \[self\]
rayQuery.from = from
[rayQuery.to](http://rayQuery.to) = to
var raycastResult = space.intersect\_ray(rayQuery)
print(raycastResult)
if !raycastResult.is\_empty():
	navigation\_agent.set\_target\_position(raycastResult.position)

Use params.collision_mask to indicate on which layers to allow collisions.

On in your case, rayQuery.collision_mask

1 Like

I see. Thank you very much for the speedy reply and helping this absolute noob :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.