Best way to move the character

What is the best way to move the character while its touching the ground? Im trying to make a rolling ability, but i dont know what i should use to move the character.

I want rolling like in Egg Hunt 2018

EDIT: Please give me an ID for a rolling sound if you find one D:

5 Likes

You could use body position to move the character.

There is an option in Humanoid API that allows it to move to a certain point. Hence the code piece:

Humanoid:MoveTo(Vector3.new(0,0,0))

Find a way to prevent the player from interfering with the move to, and then you can simply modify the walk speed and your rolling ability should be alright.

2 Likes

You could use a BodyVelocity here’s an example of what you can achieve with a body velocity; https://gyazo.com/115ca7e9d7f01882aaa6acd096be8a64

It’s quite a simple script as well;
local BV = Instance.new(“BodyVelocity”)
BV.MaxForce = Vector3.new(1e5,1e3,1e5)
BV.Velocity = Player.Character.HumanoidRootPart.CFrame.lookVector * 50
BV.Parent = Player.Character.HumanoidRootPart

4 Likes

This is what I do in my games. To disable user input:

ContextActionService:BindAction( -- Disable all player input
    'FREEZE_ACTION',
    function() return Enum.ContextActionResult.Sink end,
    false,
    unpack(Enum.PlayerActions:GetEnumItems())
)

and to allow user input:

ContextActionService:UnbindAction('FREEZE_ACTION')
6 Likes

Ah, I’ve only used context action service once. What does the result of sink do? As well as unpack?

This will help OP too as he may be unfamiliar.

BodyVelocity has a problem of incorporating the object’s mass (as well as all the masses of the welded parts). I think OP would do best to avoid that if he doesn’t want to spend some time guessing and checking.

2 Likes

Returning sink for a context action prevents it from being ran (the name is literal - it sinks the input). Unpack takes an array and returns the elements in it.

Thanks. So basically the context action is sinking all the input from all the possible player actions. I assume this is placed at top priority?

No. BindAction automatically binds it to default priority, which is 2000. Actions can be ran with a higher priority, sink will only sink inputs that are 2000 or of a lower priority (if I recall correctly). To change priorities, use BindActionAtPriority. You’ll have to shift the last argument though: argument 4 will become the priority (Enum.ContextActionPriority.EnumItem.Value) and argument 5 will become the inputs that can trigger the bound action.

2 Likes

Im VERY unfammiliar with this.
Is there a way to disable only walking with this?

You can always change the players humanoid walkspeed to 0.

1 Like

This would be interrupted by the player input. If the player is trying to move and then roll, the moveto is canceled by the fact that you’re trying to move in different directions etc. As soon as it detects input, it stops.

…If you modify the walkspeed to 0, the player cant move at all. MoveTo operates on the humanoid’s walkspeed. It’s not a measurement of how much the client can control it, it’s a measurement of how much it’s allowed to move at all. So using MoveTo and having the walkspeed to 0 stops the character from moving; making this method invalid.

Its kinda sad actually. MoveTo was the best solution to this, but interrupting it ruins it.

This would be the solution, however, if you crash into something with this, you will glitch out.

I realize that MoveTo would be interrupted by player input.
Hence:

and

And you completely missed my point with modifying the walkspeed. If the OP used the method above to prevent any inputs, walkspeed can now be used as a measure of how quick the roll is. He could change it to 30, have the player MoveTo a point infront of them.

My intention was not to block input by making walkspeed 0 but rather to make walkspeed become, in a sense, roll speed and block input by another means, like the method above.

Sorry If I was not clear, but I thought the couple of replies to my post would’ve made it clear.

1 Like

I already tried this and the only issue is that if you hold W and roll, after your character is done rolling, your character wont be moving forward, so you need to stop holding W and then hold it again wich will get annoying

1 Like

There’s ways to prevent glitching out from crashing into parts, I’ll be using the same example as yesterday but with increased velocity; https://gyazo.com/b31684fa86cc80e1a93e2346a6994afc

As you can see I’m going pretty fast yet not glitching out. The way to do this is pretty easy, simply keep the MaxVelocity low. You can always increase the velocity to your liking but keep the MaxVelocity low to reduce the chances of getting flunged/glitched out.

local bodyvel = Instance.new(“BodyVelocity”)
bodyvel.MaxForce = Vector3.new(1e5,1e3,1e5) – This is what you want to keep low
bodyvel.Velocity = character.HumanoidRootPart.CFrame.lookVector * 120 – You can play around with this to fit it to your liking

3 Likes

now its VERY glitchy, sure, if i crash into a wall i dont start flopping everywhere, BUT now the character slides to the side randomly, and sometimes the character rolls very far, and sometimes just a bunch of studs

Not sure if this is a possible fix.

But since it’s just a rolling ability you could just check that the player is moving, increase the walkspeed to what you want, and play the animation. Once the animation is done you can lower the walkspeed.

It’s a hacky solution sure, but in the mean time it will produce some decent results.