概要
API 参考
属性
方法
GetPivot
返回
代码示例
简单角色传送
-- 这段代码应该放在 StarterPlayerScripts 下的 LocalScript 中
local Players = game:GetService("Players")
local ContextActionService = game:GetService("ContextActionService")
local player = Players.LocalPlayer
local function doTeleport(_actionName, inputState, _inputObject)
local character = player.Character
if character and character.Parent and inputState == Enum.UserInputState.Begin then
-- 在角色面朝的方向将角色向前移动 10 studs
local currentPivot = character:GetPivot()
character:PivotTo(currentPivot * CFrame.new(0, 0, -10))
end
end
ContextActionService:BindAction("Teleport", doTeleport, true, Enum.KeyCode.F)PivotTo
参数
返回
()
代码示例
简单角色传送
-- 这段代码应该放在 StarterPlayerScripts 下的 LocalScript 中
local Players = game:GetService("Players")
local ContextActionService = game:GetService("ContextActionService")
local player = Players.LocalPlayer
local function doTeleport(_actionName, inputState, _inputObject)
local character = player.Character
if character and character.Parent and inputState == Enum.UserInputState.Begin then
-- 在角色面朝的方向将角色向前移动 10 studs
local currentPivot = character:GetPivot()
character:PivotTo(currentPivot * CFrame.new(0, 0, -10))
end
end
ContextActionService:BindAction("Teleport", doTeleport, true, Enum.KeyCode.F)