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?

robloxでassistant その98

Last updated at Posted at 2024-06-02

概要

robloxでassistantやってみた。
練習問題やってみた。

練習問題

ライントレースロボットを、シュミレーションせよ。

手順

  • ServerScriptServiceに、scriptを追加。
  • スクリプトを書く。

local d0 = Instance.new("Part", workspace)
d0.Anchored = true
d0.Size = Vector3.new(1, 1, 1)
local road0 = Instance.new("Part", workspace)
road0.Anchored = true
road0.Size = Vector3.new(12, 1, 4)
road0.CFrame = CFrame.new(0, 1, -20) * CFrame.Angles(0, math.rad(90), 0)
road0.Name = "road"
local road1 = Instance.new("Part", workspace)
road1.Anchored = true
road1.Size = Vector3.new(12, 1, 4)
road1.CFrame = CFrame.new(-20, 1, -20) * CFrame.Angles(0, math.rad(90), 0)
road1.Name = "road"
local road2 = Instance.new("Part", workspace)
road2.Anchored = true
road2.Size = Vector3.new(24, 1, 4)
road2.CFrame = CFrame.new(-10, 1, -28) * CFrame.Angles(0, math.rad(0), 0)
road2.Name = "road"
local road3 = Instance.new("Part", workspace)
road3.Anchored = true
road3.Size = Vector3.new(24, 1, 4)
road3.CFrame = CFrame.new(-10, 1, -12) * CFrame.Angles(0, math.rad(0), 0)
road3.Name = "road"
local part = Instance.new("Part", workspace)
part.Position = Vector3.new(-10, 2, -12)
local s = 0
while true do
	local rayOrigin = part.Position + Vector3.new(math.cos(math.rad(s)) * -2, 0.1, math.sin(math.rad(s)) * 2)
	local rayDirection = part.Position + Vector3.new(math.cos(math.rad(s)) * -2, -10, math.sin(math.rad(s)) * 2)
	d0.Position = part.Position + Vector3.new(math.cos(math.rad(s)) * -2, 2, math.sin(math.rad(s)) * 2)
	local raycastResult = workspace:Raycast(rayOrigin, rayDirection)
	if raycastResult then
		if raycastResult.Instance.Name == "road" then
			part.Velocity = Vector3.new(math.cos(math.rad(s)) * -6, 0.3, math.sin(math.rad(s)) * 6)
			print("run")
		else
			part.Velocity = Vector3.new(math.cos(math.rad(s)) * 4, 0, math.sin(math.rad(s)) * -4)
			s += -12
			part.CFrame = part.CFrame * CFrame.Angles(0, math.rad(-12), 0)
			print("tern")
		end
	end
	wait(0.1)
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?