概要
robloxでassistantやってみた。
練習問題やってみた。
練習問題
飛べ。
手順
- ReplicatedFirstに、localscriptを追加。
- スクリプトを書く。
local camera = game:GetService("Workspace").CurrentCamera
local character = game:GetService("Players").LocalPlayer.Character or game:GetService("Players").LocalPlayer.CharacterAdded:Wait()
local hrp = character:WaitForChild("HumanoidRootPart")
local humanoid = character:FindFirstChildOfClass("Humanoid")
local bodyGyro = Instance.new("BodyGyro")
bodyGyro.MaxTorque = Vector3.new(1, 1, 1) * 10^6
bodyGyro.P = 10^6
local bodyVel = Instance.new("BodyVelocity")
bodyVel.MaxForce = Vector3.new(1, 1, 1) * 10^6
bodyVel.P = 10^4
local movement = {
forward = 0,
backward = 0,
right = 0,
left = 0
}
bodyGyro.Parent = hrp
bodyVel.Parent = hrp
bodyGyro.CFrame = hrp.CFrame
bodyVel.Velocity = Vector3.new()
local function movementBind(actionName, inputState, inputObject)
if inputState == Enum.UserInputState.Begin then
movement[actionName] = 1
elseif inputState == Enum.UserInputState.End then
movement[actionName] = 0
end
local isMoving = movement.right + movement.left + movement.forward + movement.backward > 0
return Enum.ContextActionResult.Pass
end
local function onUpdate(dt)
local cf = camera.CFrame
local direction = cf.RightVector * (movement.right - movement.left) + cf.LookVector * (movement.forward - movement.backward)
if direction:Dot(direction) > 0 then
direction = direction.Unit
end
bodyGyro.CFrame = cf
bodyVel.Velocity = direction * humanoid.WalkSpeed * 3
end
game:GetService("ContextActionService"):BindAction("forward", movementBind, false, Enum.PlayerActions.CharacterForward)
game:GetService("ContextActionService"):BindAction("backward", movementBind, false, Enum.PlayerActions.CharacterBackward)
game:GetService("RunService").RenderStepped:Connect(onUpdate)
写真
以上。