I am making a simple custom control script that allows movement via the wasd keys.
Initially I was using CFrames to move the character forward/backward like so:
torso.CFrame = torso.CFrame + torso.CFrame.lookVector
But I wanted to try using Velocity to move the character instead since using the lookVector of the CFrame to move the character was pretty buggy:
torso.Velocity = torso.CFrame.lookVector * 50;
However even this method of movement is buggy; although it does not allow a user to walk through a wall, users can still experience odd behavior such as blocky movement when moving up a ramp.
To summarize, what is the most effective method to move a character from a custom control script?
Thanks
If you want to move the character as in similar to teleportation, set it's CFrame
.
torso.Position = CFrame.new() -- place a vector3 value inside the parenthesis or a object's position
If you want to move the character as in making it walk on it's own, use the :MoveTo
feature or set it's WalkToPoint
property.
torso.Parent.Humanoid:MoveTo() -- set a vector3 value or object's position
Additionally, if you want it to move intelligently like it able to cross through a maze or complicated area, you would use the pathfinding service.
pathfindingService = game:GetService("PathfindingService") pathfindingService.EmptyCutoff = 0.19 -- how small the voxels can be so the pathfinding service can determine that it's empty.
The pathfinding service works by creating a path of parts that the humanoid would follow. Basically, there is a path created by the server and the humanoid follows it by the script's command.