I’m currently making a rolling animation for my character. When rolling, the player will move towards a location in front of them over the duration of the animation. I currently use BodyMovers but I am having a hard time adjusting the forces to accomplish the goal within the animation duration. I want the speed to be constant (if the animation still plays but the character has reached its end position, keep the character in place). Using BodyMovers also causes the character to launch aimlessly when hitting a wall.
function ActionService:Tumble()
if ActionService.InAction or ActionService.ForbiddenPoses[Modules.AnimationService.CurrentPose]
or not ActionService.Armed then
return
end
--Raycast forwards to find end location.
local Raycast = Ray.new(Modules.CharacterService.HRP.Position, Modules.CharacterService.HRP.CFrame.LookVector * ActionService.TumbleLength)
local _, Position = workspace:FindPartOnRay(Raycast, Modules.CharacterService.Character)
local BodyPosition = Instance.new("BodyPosition")
BodyPosition.Position = Position
BodyPosition.MaxForce = Vector3.new(10000,10000,10000)
BodyPosition.D = 1
Modules.AnimationService:PlayAnimation("Tumble", false)
Modules.AnimationService.StateConnections.Tumble = Modules.AnimationService.SpecialPlayingAnimation.KeyframeReached:Connect(function(Keyframe)
if Keyframe == "Started" then
ActionService.InAction = true
BodyPosition.Parent = Modules.CharacterService.HRP
Modules.CharacterService.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
Modules.CharacterService.Humanoid.WalkSpeed = 0
elseif Keyframe == "Ended" then
ActionService.InAction = false
BodyPosition:Destroy()
Modules.CharacterService.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)
Modules.CharacterService.Humanoid.WalkSpeed = 14
Modules.AnimationService.StateConnections.Tumble:Disconnect()
Modules.AnimationService.StateConnections.Tumble = nil
end
end)
end
How are you planning on moving the player? Using velocity or a raycast ahead of them to know where the final position will be?
If you use velocity, you just need to get the distance of the roll. Then, you calculate the speed by dividing distance / length of animation. Then, you set the player’s velocity to the resulting speed every frame for the duration of the animation.
If you use a raycast, you can simply lerp the start position of the torso (or any part that is convenient) to the end position over the duration of the animation. With a percentage based off of the animation’s length.
well you could try creating a Cframe from the humanoid root part cframe and then you rotate the Cframe on the y axis so its facing the same direction as the torso, like this for example
local Cframe = Character.PrimaryPart.CFrame
Cframe = Cframe*CFrame.Angles(0,math.rad(Character.Torso.Orientation.Y),0)
--then you use this Cframe's look vector