mirror of
https://github.com/1bardesign/batteries.git
synced 2024-11-22 14:14:36 +00:00
fixed intersect.bounce_off bouncing if the velocity was already going away from the normal
This commit is contained in:
parent
658c8e7117
commit
c0847e1955
@ -508,11 +508,14 @@ function intersect.bounce_off(velocity, normal, conservation)
|
||||
conservation = conservation or 1
|
||||
--take a copy, we need it
|
||||
local old_vel = velocity:pooled_copy()
|
||||
--heading into the normal
|
||||
if old_vel:dot(normal) < 0 then
|
||||
--reject on the normal (keep velocity tangential to the normal)
|
||||
velocity:vector_rejection_inplace(normal)
|
||||
--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
|
||||
old_vel:release()
|
||||
return velocity
|
||||
|
Loading…
Reference in New Issue
Block a user