While I am not sure, I think there are a couple things that could be causing the behavior.
(I'm by no means an expert at Godot, or with computer physics, so I could be completely wrong!)
One thing that could be causing this to happen is that you are interacting with a physics object in _process
instead of _physics_process
.
One is that _process
is called every time a frame is drawn on the screen, while the physics engine updates several times every second (the rate physics updates is defined in the project settings). Because of this, if you are going to change something that uses physics, you really should be changing it in _physics_process
whenever possible, as _physics_process
is called every time the physics engine updates, not every time a frame is drawn.
Because you are using _process
with a RigidBody, it is quite possible that the RigidBody is moving using the physics while you are translating it through 3D space. If I recall correctly, many of Godot's internals are multi-threaded, meaning it's quite possible that more than one process is acting on the same object at the same time.
In theory, all you would have to do is replace _process
with _physics_process
and the issue may just go away like that.
Another reason you could be getting that result is due to the physics object you are interacting is a RigidBody.
RigidBody nodes are not really designed to be moved around using Translate
or similar functions, but rather designed to have impulses applied to them to move them around when possible. The general idea behind using a RigidBody is because you want the physics engine to handle the movement of the object in 3D space, and you just interact with it when needed through functions like apply_impulse
.
If you need to move the RigidBody directly, there are several ways to go about this, but the general idea is to disable the Rigidbody, move it, and then re-enable the RigidBody again. This is so the physics engine does not get in the way and cause problems when moving the RigidBody.
If you are wanting to control the movement of the RigidBody but still get physics interactions (like collisions between physics objects), I would highly suggest using a KinematicBody instead, and then using the move
and/or move_and_slide
functions. If you do not need the physics body to do anything but be a barrier, then I would suggest using a StaticBody and moving it around as needed.
Looking at the code you are using, I think you'll probably want to use a KinematicBody, or a RigidBody in Kinematic mode, instead of a RigidBody.
If you have not looked at the Physics Introduction section of the documentation, I would highly suggest giving it a look as it may be able to help you narrow down if you are using the correct physics body for what you are trying to achieve, which I think is probably the major cause of the problem.
Hopefully this helps :smile: