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 …