Hi, I want to know how I can move the player who slashed someone forward and the enemy thats being slashed backward. I have the mechanics done and I just want to know the method used in this video:
You can see the sphere moving forward smoothly every slash
You can probably have it be animation driven, or have some sort of sine movement that you’d calculate over runtime.
I guess as a starter, something like this:
local max_distance = 5 -- // Studs
local play_duration = 0.35 -- // Seconds
local move_direction = Vector3.zAxis -- // the character's look/attack direction
local PI = math.pi
local sin = math.sin
local start_time = os.clock()
local function toSine(amplitude : number, alpha : number) : number
return amplitude * sin(alpha * PI)
end
local c : RBXScriptConnection
c = RunService.Stepped:Connect(function()
local alpha : number = (os.clock() - start_time)/play_duration
local added_distance : Vector3 = move_direction * toSine(
max_distance,
math.min(alpha, 1)
)
-- // Apply to your root part or something
if (alpha >= 1 then c:Disconnect(); return end
end
The calculations are completely up to you though… You can also do this with acceleration & velocity, or just a basic sine / cosine like here.
You can use a very powerful BodyVelocity and use Debris to make it only last a very very short amount of time. This is what I do in my game to create a forward attack.
Is your MOVE_DIRECTION variable, the attacker’s move direction? Maybe switching that to the root part’s look direction or the direction between attacker and receiver.