Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What is the best method to *move* a character?

Asked by
movsb 242 Moderation Voter
7 years ago
Edited 7 years ago

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

0
Humanoids have MoveTo: http://wiki.roblox.com/index.php?title=API:Class/Humanoid/MoveTo or Move: http://wiki.roblox.com/index.php?title=API:Class/Humanoid/Move lukeb50 631 — 7y
0
@luke thanks! movsb 242 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

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.

Ad

Answer this question