Raycast not colliding when there's a collision

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By jee_gbg

Hello, i’m working on a IA for a enemy, and i have a problem that blows my mind with raycasts.

For some reason, my RayCast isn’t colliding with anything, i have tried with both bodys and areas checked and it doesn’t collide.

Yes, i’m aware that RayCast info is only updated per physics frame, i’m forcing the raycast’s update when needed. This is my code.

        Vector3 rotation = this.LeftRay.Rotation;
        Vector3 castto= this.LeftRay.CastTo;
        this.LeftRay.CastTo = new Vector3(position.x,position.y,position.z+this.LeftRay.Translation.z);
        this.LeftRay.Rotation = new Vector3(0,0,0);

        this.LeftRay.ForceRaycastUpdate();
        GD.Print(this.LeftRay.CastTo);
        if(this.LeftRay.IsColliding()){
            toreturn = true;
        }
        this.LeftRay.CastTo = castto;
        this.LeftRay.Rotation = rotation;
        this.LeftRay.ForceRaycastUpdate();

This is code for a collision checker, it checks if there’s a collision between the enemy and a given position, LeftRay is the Ray’s node, and position is the given position, in Vector3.

I’m using c# but i think is very easy to translate to GDScript if you aren’t familiar with c#.

Thanks! Sorry for my bad english.

edit: i’m actually using godot 3.2.3 mono, not 3.3.3 mono.

raycast “Enabled” == true ??
sometimes we forget to do it “true” that’s why i asked

ramazan | 2021-12-22 19:38

Yes, “Enabled” is checked, i checked that like 10 times

jee_gbg | 2021-12-22 23:03

Mabey its the collision layers/masks?

Merlin1846 | 2021-12-23 05:33

Idk, i don’t touched the collision layers, i think that isn’t the problem. I will later try to update the project to a newer version of the engine but i don’t think that’s the problem.

jee_gbg | 2021-12-23 10:10

:bust_in_silhouette: Reply From: MaxODev

Hi! I know I’m late, but I’ve faced the same issue.
The thing is that I wanted my RayCast to collide with an Area, but I haven’t checked the “Collide With → Areas” in the Raycast Inspector. So, it detected collisions with bodies, but not areas.

Hope it’ll be useful for somebody.

1 Like