I’m currently working on a football game. When the player kicks the ball, the ball should go where the camera is facing. So when I’m not moving, the shooting goes as intended. However, when I shoot while moving, the accuracy of LookVector is very questionable.
Why does the ball not go in the same direction as the gray trajectory estimation line? How can I solve this issue?
Code:
local lookVector = game.Workspace.CurrentCamera.CFrame.LookVector
local force = Vector3.new(lookVector.X, 0, lookVector.Z).Unit * power + Vector3.new(0,highPower,0)
ball:ApplyImpulse(ball:GetMass() * force)
It seems the ball is inheriting the velocity of the player. Remove the .Unit from the force a nd the lookvector is already a unit vector and instead of cameras look vector use the humanoidrootpart’s lookvector.
Instead of ApplyImpulse here I would just explicitly set the AssemblyLinearVelocity which would remove any velocity inheritance issue you’re having. Also, you don’t need to take mass into account with AssemblyLinearVelocity, mass being considered is one of the big selling points of ApplyImpulse.