I’m currently making a Dragon Ball-style combat system and I want to create a knockback effect where the enemy gets sent flying far away for a few seconds — like in the anime/games. During that time, I want the player to be able to react (like teleport to the enemy, continue a combo, etc.).
Should I use BodyVelocity, TweenService, LinearVelocityor another method to make it smooth and reactive?
Any ideas or examples would be really helpful, thanks!
I’m relatively new to scripting and especially physics-based coding, but just a warning I wouldn’t tween it since I believe that it is more for base parts and it would be harder to animate a character with tweens. Body Velocity and other Body Movers were deprecated and have been superseded by Linear Velocity and others (as it seems you already know). Unfortunately, I can’t really give you a confident answer to your question, but I would probably utilize AssemblyLinearVelocity since it’s more for when you only need a quick boost of speed. There are much more qualified people for this, but that’s what I think you should do.
BodyVelocity is deprecated, so I wouldnt recommend using it. LinearVelocity and LinearForce are the way to go. theyre much easier to control than TweenService. If you want it to be smooth and reactive, I would probably recommend LinearForce over Velocity, but you’ll have to do things like calculate mass for consistency.
A simple system you can do is :applyImpulse() on the root part. You can use BodyVelocity as well, because even though its deprecated, from my own personal experience, LinearVelocity behaves really weirdly compared to BodyVelocity. If you use applyImpulse(), you should handle it on client rather than the server. I wrote a function to help you get started, but you should know that without calculating the total mass of the local character, the results are probably gonna be unpredictable and weird
function applyKnockback(origin:Part,force:number)
local me:Model = game.Players.LocalPlayer.Character
-- wrote this in like 5 minutes, it doesn't account for the mass of the local character
me.PrimaryPart:ApplyImpulse(origin.CFrame.LookVector*force)
end