'Seamless' MoveTo() character

I’m not quite sure what else to call this.

I’m trying to make some sort of ‘vaulting’ system, or in other words, get the player’s character from Point A to Point B seamlessly, without interruption. Right now, I’m using the MoveTo() function on the player’s humanoid. Now, usually, players can interrupt a MoveTo() on their character by simply moving on their own. To prevent players from being able to move on their own, I disabled their ControlModule (found in Player/PlayerScripts/PlayerModule) while the MoveTo is occuring. Now, this works, but I want to do better.

There’s a slight issue. Say, I run a MoveTo() on the player’s character to get to a point. To avoid interruption, I disable their ControlModule while the MoveTo() is occurring. The MoveTo ends, the character stops moving, and I re-enable the player’s ControlModule. Seems fine, right? There’s a small roblox related issue. Suppose the player holds the ‘W’ key while the MoveTo() is occurring. Because the ControlModule is disabled, this doesn’t interrupt the MoveTo(). But, once the MoveTo ends, even though ControlModule gets re-enabled, the player stops moving, even though the player is holding ‘W’. The player has to let go of the ‘W’ key and press it again in order to move.

My question is, is there any way to fix this problem, or do I have to use another method instead of MoveTo()? I’ve thought of maybe using a BodyForce to move the character towards a point instead of MoveTo, but that seems too tedious. Please let me know if there’s a way to fix this issue.

Thanks. :slightly_smiling_face:

3 Likes

Hey! I’ve posted a response on how to seamlessly teleport a user between two parts, you can check it out here!

The code you’ll want is here,

local character = player.Character or player.CharacterAdded:Wait()
local currentPlatform = game:GetService("Workspace"):WaitForChild("ElevatorFloor1") -- The floor of the elevator you're currently in.
local goingPlatform = game:GetService("Workspace"):WaitForChild("ElevatorFloor2") -- The floor of the elevator you're going to

local offset = target.CFrame:toObjectSpace(character:WaitForChild("HumanoidRootPart").CFrame)
character:WaitForChild("HumanoidRootPart").CFrame = goingPlatform  * offset

This doesn’t use MoveTo rather it just sets the RootPart’s CFrame to a location! Hope this helps, if not shoot back a response.

3 Likes

There’s a chance that ControlModule:GetMoveVector will return what direction the player’s character is supposed to move, if any key is held.
If it does, you can call humanoid:Move(moveVector, true) to move the humanoid in the correct direction.

1 Like

Hey man, thanks for responding!
Teleporting the player isn’t quite what I’m looking for. I’m trying to move the character from Point A to Point B smoothly, not just teleport them there. The video below pretty much shows what I’m trying to accomplish.

(The name of the game is ‘Dead by Roblox’.)
I’m trying to move a player from one side of the window to the other. However, I want the player to be able to move right after the MoveTo without having to let go of whatever movement keys they’re pressing and press them again.

Good idea! Unfortunately, I gave this a shot, but if it’s called after the MoveTo(), when ControlModule is re-enabled, it just returns (0,0,0), and the player doesn’t move. I feel like this is on the right track, though. Figuring out where the player is supposed to move and then moving them there.

In that case, you could try manually figuring out direction using UserInputService:IsKeyDown(keyCode):

local UIS = game:GetService("UserInputService")

local KC = Enum.KeyCode
local ZERO = Vector3.new()

local moveVector =
    (UIS:IsKeyDown(KC.W) and Vector3.new(0, 0, 1) or ZERO) +
    (UIS:IsKeyDown(KC.A) and Vector3.new(1, 0, 0) or ZERO) +
    (UIS:IsKeyDown(KC.S) and Vector3.new(0, 0, -1) or ZERO) +
    (UIS:IsKeyDown(KC.D) and Vector3.new(-1, 0, 0) or ZERO)

humanoid:Move(moveVector, true)

I never remember which direction is which for each key, so correct it if necessary.
You could probably also use UserInputService to find current position for other platforms too, e.g. GetGamepadState