The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

I'm trying to find a way I can write a script that detects a collision directly from StaticBody3D or CollisionShape3D. Currently I'm using CharacterBody3D physics update to check for collision against a stage exit portal.

private void CheckForStageExit() {
        for (int index = 0; index < GetSlideCollisionCount(); index++) {
            // We get one of the collisions with the player.
            KinematicCollision3D collision = GetSlideCollision(index);
            // If the collision is with a mob.
            if (collision.GetCollider() is StaticBody3D) {
                StaticBody3D temp = (StaticBody3D)collision.GetCollider();
                if (temp.Name == "StageExit") {
                    GD.Print("StageExit");
                }
            }
        }
    }

This method does work but it will become cumbersome with the more stages I add to the game. I'd like a way to add a script directly to my static body that can raise an event when the player body enters, like with rigid body enter event. I'm not sure if this is even possible if it I'd like to know how it's done.

Godot version 4.03
in Engine by (12 points)

This seems like a function of the player (or one of its components) to check for body_entered as it would any other body, switch on collision type/group. Perhaps if you wish to keep this method, use groups instead of individual names or even the type (e.g. if (collision.GetCollider() is StageExit stageExit) { /* stuff */ }.

Unless I’ve misunderstood?

I'd like to have something similar to body enter on my collision shape. This way I could check if the play has entered when the event is raised. I know it can be done by adding a rigid body but since the object is static it doesn't need a rigid body.

If you have used Unity you may be familiar with the on collision enter method. It doesn't require a rigid body just a mesh with a shape. Something similar to this.

Sure, but the other way around; a static body doesn’t have these event but a rigid body colliding with them does, e.g. the player or some other thing monitoring a rigid body. Switch the logic around, only the thing moving really matters.

If the logic must go in the static body thing then an area (e.g. like a Unity trigger) can detect bodies and might be worth considering.

Please log in or register to answer this question.

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.