Hello, recently I’ve been working on a 3D platforming system which is intended to be incredibly fast paced. In the game, holding jump allows you to instantly bounce off a wall and continue moving with most of your momentum.
However, diagonal parts meddle with the physics I coded into the system. I multiply Vector3 values to reverse momentum directed towards the face the player bounces off. I’ve been trying to find a way to reflect the player’s momentum relative to the surface they bounce off.
I’ve tried using If statements to check if the surface the player is bouncing off is diagonal, but this can’t account for stronger angles, only 45 degree angles, and only from one side.
This is currently the system I use whenever a player bounces off of a wall. This is used to change a VectorForce and the player’s velocity.
Normalize = function(Normal, Vel) -- Normal refers to the surface's normal ex. (0,0,-1) (facing front)
local NeoNormal = Vector3.new(1,0,1) - Vector3.new(math.abs(Normal.X),math.abs(Normal.Y),math.abs(Normal.Z))*2.55
local NeoVel = Vel*NeoNormal
if math.abs(Normal.X) > 0 and math.abs(Normal.Z) > 0 then -- Code intended to account for angles.
NeoVel = Vector3.new(NeoVel.Z,NeoVel.Y,NeoVel.X)
end
print(NeoNormal)
if NeoVel.Magnitude > 300 then
NeoVel = NeoVel.Unit * 300
elseif NeoVel.Magnitude < 50 then
NeoVel = NeoVel.Unit * 50
end
return NeoVel
end