var movement := current_velocity * delta
target_position = to_local(global_position + movement)
force_shapecast_update()
if is_colliding():
for ci in get_collision_count():
var c = get_collider(ci)
var cp = get_collision_point(ci)
if c is RigidBody3D:
var f = movement
c.apply_force(f, cp)
# Stop the bullet for debugging
set_physics_process(false)
global_position += movement * get_closest_collision_safe_fraction()
# Blue velocity indicator
vel_ind.look_at(global_position + movement)
If you couldn’t tell, the way the player is facing globally, impacts the force added to the RigidBody.
This is not intended, and there’s no code there to make that happen. Velocity is in global coordinates, and even shows up correctly when the bullets impact.
Why it chooses to rotate differently is a mystery to me.
That’s correct. I read the add_force doc and thought it’s correct since it says global coordinates which the collision point is in. Apparently it meant global coordinates relative to the position of the RigidBody. Basically local coordinates, but without the rotation. Which is why c.to_local() didn’t work either.
Although about apply_impulse; The bullet is meant to apply a force every frame that it’s inside the RigidBody. I’m not sure if applying an impulse is correct or applying a force. Would I apply an impulse every frame instead? apply_force isn’t really giving the desied behavior either when accounting for the bullet’s mass. apply_impulse looks correct in this case, it would be too much if applied every frame.