Hello everyone.
i was trying to create a knockback roll similar to many battlegrounds games, but i ran into an issue and some… complications?
anyways, when the player hits the ground, the vectorvelocity designed to push the player back actually forces them into the floor. i tried reducing maxforce, except… at that point it wont roll the player back at the desired speed.
here is the module:
local AnimateModule = game:GetService("ReplicatedStorage").AnimationModules.JointAnim
local RollPushBack = {}
function RollPushBack.Push(Humanoid : Humanoid, Velocity : number, Base : Part, Part : Part, Raise : boolean)
local TS = game:GetService("TweenService")
local Up : Vector3
local Down : Vector3
local AnimTable = {
["Float"] = 'rbxassetid://85016151310429',
["Land"] = 'rbxassetid://86230451638966'
}
if Raise == true then
Up = Vector3.new(0, 30, 0)
Down = Vector3.new(0, 80, 0)
else
Up = Vector3.new(0, 0, 0)
Down = Vector3.new(0, 80, 0)
end
local Direction = -((Base["Position"] - Part["Position"])["Unit"] * Velocity) + Up
local DownTween = -((Base["Position"] - Part["Position"])["Unit"] * Velocity)/1.5 - Down
local LandedTweenStart = Vector3.new(Direction["X"], 0, Direction["Z"])
print(LandedTweenStart)
local LandedTweenEnd = Vector3.new(0, 0, 0)
local AttachmentZero = Instance.new("Attachment")
AttachmentZero["Parent"] = Part -- part is the enemy's hrp btw
local LV = Instance.new("LinearVelocity")
LV["Attachment0"] = AttachmentZero
LV["MaxForce"] = 100000
LV["RelativeTo"] = Enum.ActuatorRelativeTo.World
LV["VectorVelocity"] = Direction
LV["Parent"] = Part
LV["ForceLimitsEnabled"] = true
Part["CFrame"] = CFrame.lookAt(Part["Position"], Base["Position"])
local Tween = TS:Create(LV, TweenInfo.new(5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {VectorVelocity = DownTween})
Tween:Play()
local CastParams = RaycastParams.new()
CastParams.FilterType = Enum.RaycastFilterType.Include
CastParams.FilterDescendantsInstances = {workspace.Map}
for _, Animation in pairs(Humanoid["Animator"]:GetPlayingAnimationTracks()) do
Animation:Stop()
end
local Float : AnimationTrack = require(AnimateModule).Animate(Humanoid, AnimTable["Float"])
repeat
wait()
until Humanoid:GetState() == Enum.HumanoidStateType.Landed or workspace:Raycast(Part["Position"], Vector3.new(0, -3, 0), CastParams)
LV["VectorVelocity"] = LandedTweenStart
for _, Animation in pairs(Humanoid["Animator"]:GetPlayingAnimationTracks()) do
Animation:Stop()
end
local Roll : AnimationTrack = require(AnimateModule).Animate(Humanoid, AnimTable["Land"])
local function Rolling()
local Time = Roll["Length"] - Roll:GetTimeOfKeyframe("SLOWING")
print(Time)
local Tween = TS:Create(LV, TweenInfo.new(Time, Enum.EasingStyle.Linear, Enum.EasingDirection.Out), {VectorVelocity = LandedTweenStart})
Tween:Play()
Tween.Completed:Connect(function()
LV:Destroy()
AttachmentZero:Destroy()
end)
end
Roll:GetMarkerReachedSignal("Slowing"):Connect(Rolling)
end
return RollPushBack
i can show other parts of this system as well if required.
unfortunatly, i dont know how to screen record on windows.
any assistance is appreciated.