How would I make a player constantly move forward, and make the direction depend on the HumanoidRootPart look vector
I messed around with linear velocity but to no luck,
If anyone could help that would be great.
Put the following code into a server script under Explorer > StarterPlayer > StarterCharacterScripts
-- Services
local RunService = game:GetService("RunService")
-- Variables
local Character = script.Parent
local humanoid = Character:WaitForChild("Humanoid")
local root = Character:WaitForChild("HumanoidRootPart")
-- Functions
function forceWalk()
local cf = root.CFrame * CFrame.new(0,0,-10)
humanoid:MoveTo(cf.Position)
end
RunService.Stepped:Connect(forceWalk)
Might not be the most optimal solution
Also, this doesn’t disable the players normal input, so for example, the player is able to hold down S which somewhat cancels this movement.
EDIT: Did some more research, found some stuff out.
Firstly, @SomeFedoraGuy’s idea of using Move() is much better, this is because you give the humanoid a direction to move in, as opposed to MoveTo() where you give a position to move to (obviously). So Move() makes more sense for this problem.
However, looking at the documentation:
First I tried disabling the default control scripts as suggested.
In a local script, you can do something along the lines of:
require(game.Players.LocalPlayer.PlayerScripts.PlayerModule.ControlModule):Disable()
This works in that the player’s normal movement and handling is disabled, however, when attempting to call Move() on the player humanoid I got a warning(?) about not being able to call Move() on a player with disabled control scripts.
Next I tried doing the RunService:BindToRenderStep() solution. This can only be done on the client, so I made a local script and did the following:
RunService:BindToRenderStep("move", Enum.RenderPriority.Character.Value + 1, function()
-- fire a remote event
end)
Then on a server script
remoteEvent.OnServerEvent:Connect(function(playerFired)
if player == playerFired then
--forcewalk
end
end)
If I remember correctly, doing it like this led to some jittery movement.
So OP, if you want a quick and dirty solution, I think my original post works fine - however - I’d strongly advise researching this other method, as it seems more suitable. - Thanks!