I was wondering what would be the smoothest and most effective way to move a character based on a ray shot from the character’s RootPart. This is what’s commonly known as “Knockback”, and due to the nature of my game, this knockback must be based on what a ray returns. What I have experimented with is:
Tweens
Lerp functions
:ApplyImpulse() Function
My question is what would be the best way to go about this? Many of these options are pretty jarring and don’t smoothly decelerate like “knockback” in other games.
You could try applying vector forces to the character. (This would work best in a local script on the client being knocked back) Other than this and what you’ve mentioned already there isn’t much else. Possibly one of the legacy body movers like body velocity etc…
Yeah, any character movement is handled locally for maximum smoothness, but I was just wondering if there were any other solutions or explanations based on another’s experience with raycasting knockback. ApplyImpluse() Is applying a Vector force, which Is what I am experimenting with the most currently.
Yeah thats the most likely solution since it works well with the physics engine. The deceleration is based on how parts would normally decelerate with gravity and friction.
Yep I would like to add on it’s worse with humanoids, because they provide their own “Air friction” and stuff.
So more experimentation with
-
Humanoid states (rag doll)
-
Humanoid platform stand or seated to 100% disable physics interference by humanoid (unfortunately they fall down)
Will be needed
I think maybe what you’re not happy with is that humanoids have a tendency to ignore momentum. They like to STOP the moment force is no longer applied. One way to compensate is to use vector forces directly and smoothly reduce the force after a period of time/distance
I would to add on yeah platform stand to disable physics is really important. I got curious with and without and yeah it’s really significant. The knock back was done by adding .Velocity (easier to measure without calculating impulse force).
Replication code
local RE = script.Parent.RemoteEvent
RE.OnServerEvent:Connect(function(player, hitPlayer)
local attackerHRP = player.Character.HumanoidRootPart
local hitPlayerHRP : BasePart = hitPlayer.Character.HumanoidRootPart
local direction = hitPlayerHRP.Position - attackerHRP.Position
print("Server!")
local victimHumanoid = hitPlayer.Character.Humanoid
hitPlayerHRP:SetNetworkOwner(nil)
victimHumanoid.PlatformStand = true
local trollFling = Vector3.new(-1,0,0)*50+Vector3.new(0,1,0)*25
hitPlayerHRP.AssemblyLinearVelocity += trollFling
task.wait(2)
hitPlayerHRP:SetNetworkOwner(hitPlayer)
victimHumanoid.PlatformStand = false--The other script I commented out this
print("Can walk now")
end)
Yeah, I set the humanoid state to the “Physics” state and it seems like it carried momentum a bit better than previously. Physics state should be used in preference to platform stand state due to the fact that the Physics state is never ending, while platformstanding can be interrupted.