How to prevent box clipping through the walls, with a Raycast

Godot Version

Godot 4.2.1 C#

Question

Basically, I want to prevent the box, which is set to the collision point of the raycast, from clipping through the walls as shown in the video:


I am using a StaticBody3D, switching to a RigidBody3D makes a weird offset from the raycast, and using linear velocity makes the box go crazy and move incredibly fast. I am also using Jolt physics.

Here is the movement code:

public override void _Process(double delta)
{
	var blockPosition = RayCast.GetCollisionPoint() - 0.5f * RayCast.GetCollisionNormal();
	FakeBox.Position = blockPosition + RayCast.GetCollisionNormal();
	[... rest of the code]
}

First of all: When you move physics-objects you always want to do that in _physics_process and not _process.
Second: to reduce the speed of the box you can reduce either the speed or multiply it by delta.
Third: Maybe you can use a shapecast3d. It saves all the collisions so you might be able to stop it from clipping, but im not 100% sure

shapecast3d makes the box go even crazier in terms of position, and the clipping problem still exists. i have moved to physics_process, but can’t really times it by delta when the position is a Vector3

Have you considered using a characterbody or a animatablebody?

- animatedbody
- characterbody

The animated body and character body still persists with the problem. If it helps, I’m using “Cyclops” for mapping.

I think the best try is to use move_and_slide instead of setting the position directly

that would technically “fix” the problem, but it causes a whole new one where the movement goes crazy as it’s being pushed against the wall, i kinda tried this with linearvelocity being set instead, but as i said the movement goes crazy

hmm, i dont know other solutions, maybe try a different physics-engine

i’m already using the jolt engine, so i dont know

Another option is to use a grid-based placement system, but i guess that doesnt fit your game

Did you figure out a work around to this? I have a similar issue.