How to make a somersault system?

I have been trying to do that when the player presses the E key of a somersault (Animation) and then appears in the position where the somersault ends until everything is fine but the problem is based on what makes the animation but I don’t know how to do it It stays in that position. Also, I already did the calculation of how much should be added to the Z axis, but I need the Z axis to be added or subtracted depending on where the player character is looking.

please pls help me you pleaseeeee

please i need you help pleaseeeee

I feel like what something better could be is -

When E is pressed, play a somersault AnimationTrack that has been loaded on the Humanoid or Humanoid.Animator. Then, while the animation is playing, ignore any extra E key inputs. Then, continously set the velocity of the player using LookVector and do not allow them to move until the somersault is finished.

However, maybe I read your post wrong and that’s what you’re trying to say.

1 Like

And how would I change the position?

I don’t understand what you’re trying to achieve !

Create a script on StarterCharacterScripts, which allows the player to do the animation when you press E on your keyboard

local UserInputService = game:GetService("UserInputService")

local animation = script:WaitForChild("Somersault")

local somersaultAnim = script.Parent.Humanoid.Animator:LoadAnimation(animation)

UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
    if input.KeyCode == Enum.KeyCode.E then
        somersaultAnim:Play()
    end
end)

You would simply create a somersault animation first.

Needed Resources for this Project:
UserinputService
Animation Editor

Tutorial
So firstly begin by creating a animation. Secondly create a script that detects user input and loads the animation and plays it on the humanoid. However when running this script you may notice that the position of the somersault will reset once the animation ends, this is because by default when the animation ends it resets to its original position. This means that in order to position the player you will have to play the animation wait for it to end and then set a offset from the current position.

  1. Make a somersault animation (centered around the humanoid root part)
  2. Use a LinearVelocity to move the character
  3. When the animation ends remove the LinearVelocity
1 Like

Can you tell me more or less how it is? I barely hear the linear speed

(Before you start the code you need a somersault animation)

For the code (in a LocalScript):

  • Use the ContextActionService to run a function when the E key is pressed.
  • When the E key is pressed, create a LinearVelocity and Attachment. Parent them both to the character’s humanoid root part.
  • Set the LinearVelocity’s mode to line, the line direction to Vector3.new(1,0,0), attachment 0 to the new attachment, the line velocity to the velocity you want, max force to math.huge, etc.
  • Play the animation
  • Remove both the linear velocity and attachment after a delay (distance moved is velocity * delay time)
  • Stop the animation

This is a better way to do rolling/somersaulting (IMO it’s less buggy). If you want to do it with the animation offset just set the HRP CFrame once you’re done. You can calculate the desired end CFrame with:

local endCFrame = HumanoidRootPart.CFrame + HumanoidRootPart.CFrame.LookVector * animationOffset
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.