How may I push a player to what the player is looking at?

Hi! So in my game, I’m trying to develop a telekinetic Push ability however When the player presses the keybind, The player gets pushed behind the player or some other unwanted direction. I have some understanding of lookvectors yet it doesn’t seem to work well.

This code is stored in a module script, which is triggered thru a remote event, the remote event is triggered by a local script that detects the keybind.

Thank you for anyone helping in advance.

  if victim.HumanoidRootPart and Debounce and CurrentMagic.Value >= magicInput and Distance <= 25 then 
	local Push = Instance.new("BodyVelocity")
	Push.Parent = victim.HumanoidRootPart
	Push.Velocity = (HumanoidRP.Position) + Vector3.new(30,15,30)
	
	                                                             --(X, Y, Z)
	wait(timelimit)
	Push:Destroy()
end
1 Like

First of all you’ll need to capture the player’s camera who used the ability. Send this through the remote event as LookVec

game.Workspace.CurrentCamera.CFrame.LookVector

Then, in your server script that creates the BodyVelocity, change this

Push.Velocity = Vector3.new(30, 30, 30) * LookVec

Because LookVectors are unit vectors, meaning they have a magnitude of 1, multiplying them by 30 in every direction will result in a total magnitude of 30 but directed away from the players camera.

Edit
If you want a more realistic effect, try just setting the players HumanoidRootPart.Velocity instead of creating a BodyVelocity. This will cause immediate deceleration and the player may interact with physics better.

Wow, Thank you so much! I honestly never thought about it, I tried using the look vector but on the humanoidRootPart and not on the camera which was the reason why it never worked! After a few hours of having errors while using your technique I found errors and fixed them, Thank you so much! It works really well. I had a few prohlems such as the player not levitating no matter the force or vector I added to the Y axis but fixed it by adding a bodyPosition to do a levitation effect and played an animation so that the player is knocked out. Thank you!

1 Like