Area3D not detected as collision from RayCast3d

Godot Version

4.2

Question

Hello
I’m following a well-known tutorial online, and I have a problem when detecting Area3D, which is a child of BoneAttached3D and the parent of CollisionShape3D. All of them are attached to the character, but when I try to set the layer/mask of the Area3D and the bullet RayCast3D to the same layer, it never hits. It only hits the CharacterBody3D, which is in layer 1.

This is the image with the Area3D 's

This is the bullet

And all of the Area3D are with group name “enemy”

The zombie layer and mask on 1

mesh instance also on layer 1

So now when it is got setup like this
This script never met and the bullets go through the zombie
The “if(rayCast.IsColliding())” never met .

The bullet script 

using Godot;
using System;
using System.Collections;
using static Godot.GD;

public partial class bullet : Node3D
{
	private MeshInstance3D mesh;
	private RayCast3D rayCast;
	private const float SPEED = 40.0f;
	private string nameBullet = "Bullt";
	private GpuParticles3D  particales;


	public string NameBullet
	{
		get { return nameBullet; }
	}

	// Called when the node enters the scene tree for the first time.
	public override void _Ready()
	{
		mesh = GetNode<MeshInstance3D>("MeshInstance3D");
        rayCast = GetNode<RayCast3D>("RayCast3D");
		particales = GetNode<GpuParticles3D>("GPUParticles3D");

    }

    private async void awaitWithTimeout(float f)
    {
        await ToSignal(GetTree().CreateTimer(f), "timeout");
        QueueFree();
    }

    // Called every frame. 'delta' is the elapsed time since the previous frame.
    public override void _Process(double delta)
	{
		Position += Transform.Basis * new Vector3(0, 0, -SPEED) * (float)delta;
		if(rayCast.IsColliding())
		{
			mesh.Visible = false;
			particales.Emitting = true;
			//rayCast.Enabled = false;
			Node3D collNode = (Node3D)rayCast.GetCollider();
            Print(collNode.ToString());

            foreach (var c in collNode.GetGroups())
			{
				Print(c);
			}

			if(collNode.IsInGroup("enemy"))
			{
				Print("its enemy");
				(rayCast.GetCollider() as BodyPart).Hit();

            }
            awaitWithTimeout(1.0f);
			
        }
	}

    private void _on_timer_timeout()
	{
        QueueFree();
    }
}

But is i move the layer and the mask and the raycast back to 1
The “if(rayCast.IsColliding())” do met but never go through the
“if(collNode.IsInGroup(“enemy”))” condition .
and the Print(collNode.ToString()); result is “characterbody3d” not Area3d …

1 Like

Don’t put layer and mask on the same layer. Layer is who the node itself is, Mask is who the node faces.

Also, I may not be accurate, but I assume Area3D can only track collision between Area and Body, but not Raycast. Raycast seems to be able to track collision with Body, but I don’t know about Area.

Ok i will try to separate the layer and the mask ,
im folowwing this tutorial by the way
This is the part with the layers

Regarding the raycast i do see this checkbox that can do collision on Areas
image

I changed in the zombie to :

and in the raycast it remain on 2

So the good news it coiled with the zombie , but it never getting to the code where is supposed to detect the collision …

2 Likes

It’s 6:40 and I haven’t slept yet, so I could be wrong. in Area3D’s signals it says it can call 3 types of signals area, body, body_shape and from my logical deductions, I can say that Area3D itself can’t know through signals that it’s in contact with Raycast, however Raycast can know that it’s in contact with Area3D. So, if you want to know that the two nodes are colliding, check it with the Raycast node, and then after checking it, do what you need to do. Now, I can’t help you any more, I’m sleeping :zzz:

Thanks , well the script that i presented by mistake i wrote zombie where in fact it is
the bullet script ( i fixed ) that . and it is attached to the bullet and checks if:
if(rayCast.IsColliding())

so what you saying is true im checking from the the raycast to the Area3D

1 Like