fixed intersect.bounce_off bouncing if the velocity was already going away from the normal

This commit is contained in:
Max Cahill 2022-01-20 17:37:40 +11:00
parent 658c8e7117
commit c0847e1955

View File

@ -508,11 +508,14 @@ function intersect.bounce_off(velocity, normal, conservation)
conservation = conservation or 1 conservation = conservation or 1
--take a copy, we need it --take a copy, we need it
local old_vel = velocity:pooled_copy() local old_vel = velocity:pooled_copy()
--reject on the normal (keep velocity tangential to the normal) --heading into the normal
velocity:vector_rejection_inplace(normal) if old_vel:dot(normal) < 0 then
--add back the complement of the difference; --reject on the normal (keep velocity tangential to the normal)
--basically "flip" the velocity in line with the normal. velocity:vector_rejection_inplace(normal)
velocity:fused_multiply_add_inplace(old_vel:vector_sub_inplace(velocity), -conservation) --add back the complement of the difference;
--basically "flip" the velocity in line with the normal.
velocity:fused_multiply_add_inplace(old_vel:vector_sub_inplace(velocity), -conservation)
end
--clean up --clean up
old_vel:release() old_vel:release()
return velocity return velocity