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やってみた。
練習問題やってみた。

練習問題

スクリプトだけで、自分のキャラクターをクローンして、自分を追いかけさせよ。

手順

  • ReplicatedFirstに、LocalScriptを追加。
  • スクリプトを書く。

local character = game:GetService("Players").LocalPlayer.Character or game:GetService("Players").LocalPlayer.CharacterAdded:Wait()
local Players = game:GetService("Players")
local player = Players.LocalPlayer
player.Character.Archivable = true
local clone = player.Character:Clone()
player.Character.Archivable = false
clone.Name = "npc"
clone.Parent = workspace
clone.PrimaryPart.CFrame = CFrame.new(0, 0, -50)
local hum = clone:FindFirstChild("Humanoid")
hum.DisplayName = "npc"

local PathfindingService = game:GetService("PathfindingService")
local animator = clone.Humanoid.Animator
local animation = clone.Animate.walk.WalkAnim
local animationTrack = animator:LoadAnimation(animation)
local path = PathfindingService:CreatePath()
local breakCount = 10
animationTrack:Play()

while wait(1) do
	local character = player.Character
	local humanoid = character and character:FindFirstChild("Humanoid")
	if humanoid then
		local position = character.PrimaryPart.Position
		path:ComputeAsync(clone.PrimaryPart.Position, humanoid.RootPart.Position)
		if path.Status == Enum.PathStatus.Success then
			local waypoints = path:GetWaypoints()
			for i, waypoint in pairs(waypoints) do
				clone.Humanoid:MoveTo(waypoint.Position)
				clone.Humanoid.MoveToFinished:Wait()
				if i % breakCount == 0 and position ~= character.PrimaryPart.Position then
					break
				end
			end
		end
	end
end



写真

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?