Welcome to the forums @pagavo!
This is likely due to collision tunneling, which can happen where an object moves so fast that it goes through the object and it's collision response is incorrect. Generally this leads to the object going through the other, but in this case it may be colliding and getting inside the body, so the physics engine resolves the remaining velocity and that puts it so high.
What you could try doing is checking if the velocity is over a certain speed and if it is, use multiple move_and_collide
function calls. That might fix the issue, since none of the individual move_and_collide
calls would have too high of a velocity.
Something like this (untested):
var max_velocity_speed_squared = 128*128
if (velocity.length_squared() > max_velocity_speed_squared):
var tmp = velocity
var velocity_norm = velocity.normalized()
while (tmp.length_squared() > 0):
if (tmp.length_squared() > max_velocity_speed_squared):
move_and_collide(velocity_norm * 128)
tmp -= velocity_norm * 128
else:
move_and_collide(velocity_norm * tmp.length())
tmp = Vector3.ZERO
# shouldn't be needed, but...
break
else:
move_and_collide(velocity)