Skip to main content

PlayerLocomotion.RevertLocomotionType()

Reverts the user’s locomotion type to their preferred locomotion.

Usage

---@type PlayerLocomotion
local playerlocomotion;


playerlocomotion.RevertLocomotionType()

Example

If you restrict the locomotion mode in a specific location, for example inside a collider box, the game automatically changes the locomotion for the effected players. For example, if a player’s locomotion type is Walk Mode and a code disables the Walk Mode for that player, the game will change the players locomotion type to teleport. Use this function to return the locomotion back to players’ preferred Locomotion Type.

do -- script PlayerLocomotionTrap 

-- get reference to the script
local PlayerLocomotionTrap = LUA.script;

-- when a player enters the collider
function PlayerLocomotionTrap.OnTriggerEnter(other)
-- check if the other collider is a player
if other.attachedRigidbody.gameObject.IsPlayer() then

-- get player
local player = other.attachedRigidbody.gameObject.GetPlayer();

-- check if this is the local player. The locomotion is nil for remote players.
if player.Locomotion == nil then return; end

-- disable walk mode
player.Locomotion.ToggleWalkMode(WalkMode);
end
end


-- when a player leaves the collider
function PlayerLocomotionTrap.OnTriggerExit(other)

-- check if the other collider is a player
if other.attachedRigidbody.gameObject.IsPlayer() then
-- get player
local player = other.attachedRigidbody.gameObject.GetPlayer();

-- check if this is the local player. The locomotion is nil for remote players.
if player.Locomotion == nil then return; end

-- revert locomotion values back to world default
player.Locomotion.SetWorldDefault();

-- revert players current locomotion to their preference
player.Locomotion.RevertLocomotionType();
end
end
end