I’m trying to make a knockback system with BodyVelocity. The thing is, the force is exerted only in a horizontal line. But I want it to bounce up while bouncing forward if that makes sense.
This is my attempt:
local knockback = Instance.new("BodyVelocity")
knockback.Parent = hitRootPart
local x = rootPart.CFrame.LookVector * magnitude
local y = Vector3.new(0, magnitude, 0)
knockback.Velocity = x * y
knockback.MaxForce = knockback.MaxForce * magnitude
wait()
knockback:Destroy()
1 Like
I know this is a month late but uh…
you want to get the direction the character is bouncing in first by using .Unit.
(partpushingAwayFrom - playerHumnoidRootPart.Position).Unit
then multiply it to the amount of force and set it as the bodyVelocity.Velocity
knockback.Velocity = (partpushingAwayFrom.Position - playerHumnoidRootPart.Position ).Unit * force
if you want the force to go in a particular direction you can emphasize it with something like this:
knockback.Velocity = (partpushingAwayFrom.Position - playerHumnoidRootPart.Position ).Unit * Vector3.new(force * 0, force, force * 2)
if you want to bounce the player back relative to its orientation, change the velocity of the humanoidRootPart instead of parenting a body mover to it.
2 Likes