+1 vote

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);

            toreturn = true;
        this.LeftRay.CastTo = castto;
        this.LeftRay.Rotation = rotation;

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.

Godot version Godot 3.2.3 mono
in Engine by (23 points)
edited by

raycast "Enabled" == true ??
sometimes we forget to do it "true" that's why i asked

Yes, "Enabled" is checked, i checked that like 10 times

Mabey its the collision layers/masks?

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.

1 Answer

0 votes

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.

by (14 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.