0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

robloxでassistant その93

Posted at

概要

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)




写真

image.png

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?