Checking rotation collisions using collide_shape, how to adjust the rotation from the result?

Thanks for replying! I’ll try and give some more context. I’m “new” to game dev and Godot, but I have a lot of general programming experience (I say “new” as I started about 6 months ago). I’m just messing about in my spare time for fun. So firstly, yes, I probably have managed to overcomplicate things! Probably from the start which have compounded to this :sweat_smile:

I’m making a game about trains, here was my original post where I talked about that a bit more and why I ended up manually moving RigidBody3D around a Path3D.

The first thing I noticed is you are creating a new collision shape every time you want to detect a collision. How come?

I assume you mean psqp.shape = BoxShape3D.new() in _collision_test?

The _collision_test test method I originally wrote for a ghost mode. Basically if you crash I reset you back onto the path and put you in ghost mode, which stops you from colliding. I use the _collision_test when the ghost mode timer runs out to see if you are still colliding with anything. If you are I extend ghost mode, otherwise it ends. I used a simplified box which covers the 3D model, as I didn’t need accurate checks. Given it was only used rarely I didn’t really think about the fact I was newing up a BoxShape3D every time.

As the method already existed I just tried reusing it for my rotation collision check. So for general collision detection I’m not using this method every time!

This was why my second question was about alternatives. I only used collide_shape from PhysicsDirectSpaceState3D originally as it seemed like the simplest to use for my ghost mode use case.

Just add an Area3D and CollisionShape3D to the object itself. Then use a collision layer and mask to prevent the object from passing through whatever it is hitting. If that doesn’t work, add a script to the rotating object that triggers on body_entered and just stop the rotation. Tweak your CollisionShape3D until it collides right before the object would enter, and you are done.

The object already has CollisionShape3Ds and masks etc set up. The problem is the objects also need to collide with other objects on the same Path3D. The speed at which they travel along the path is MUCH slower than the speed at which they rotate.

Currently my collision shapes are set up to handle the lower speed collisions. This means they don’t work well for the rotation collisions, as the object can rotate far into the object in a single frame. If I adjust the collision shapes to be larger so they handle the rotation collisions nicely, you end up colliding with objects on the same path earlier than you expect (i.e. before the meshes visually collide to the player).

Hopefully this makes sense, sorry for the wall of text!