The below code flings the player backwards. After some research I found that using the velocity as opposed to BodyForce was a more viable way to do this. This is due to when using BodyForce, if the player hit an object while flinging backwards, they would sporadically fling around after hitting it.
The problem that I have now is the velocity not being consistent based on I'm guessing the players height on the map. When standing on the baseplate in-game, this flings the character back several studs and works fine. If the player jumps then uses this code, they fling about four times further than if they were still grounded. Now..if they were to get on a tall object, let's say the roof of a building, and use this without jumping. It flings even FURTHER back!
What could I be doing wrong? Should I explore other ways to fling the player back? Am I calculating the Velocity wrong? Thanks in advance!
UserInputService.InputBegan:Connect(function(InputObject,Processed)
if not Processed then
if InputObject.KeyCode == Enum.KeyCode.X then
if script.Shift.Value == false then
script.Shift.Value = true
animTrack:Play()
Player.Character.HumanoidRootPart.Velocity = Player.Character.HumanoidRootPart.CFrame.lookVector*-500
wait(.4)
animTrack:Stop()
wait(3)
script.Shift.Value = false
end
end
end
end)
