본문 바로가기
Game/로블록스

로블록스(Roblox) #03 - 로블록스 게임 만들기 (둘러보기)

by 티포스터 2021. 3. 29.
728x90

게임 제작 전 미리 만들어진 템플릿을 둘러보는 것은 많은 도움이 된다.

아래 템플릿 중 Obby를 살펴보자.

 

Obby를 통해 로블록스 게임 만들기의 기초를 보자.

 

닿으면 죽는 장애물

게임을 해보면 알겠지만 빨간 블록에 닿으면 죽는다.

해당 블록을 클릭하면 이름부터 KillBrick으로 되어 있다.

KillScript를 더블클릭해서 열어보자.

 

script.Parent.Touched:connect(function(hit)
	if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
		hit.Parent.Humanoid.Health = 0
	end
end)

 

로블록스에서는 '루아(Lua)'라는 프로그래밍 언어를 사용한다.

 

 

루아 (프로그래밍 언어) - 위키백과, 우리 모두의 백과사전

위키백과, 우리 모두의 백과사전. 루아패러다임다중 패러다임: 스크립트, 명령형 (절차적, 프로토타입 기반, 객체 지향), 함수형설계자호베르투 이에루잘림스시 Waldemar Celes Luiz Henrique de Figueiredo

ko.wikipedia.org

루아 학습은 나중에 하고 위 스크립트에서 Humanoid.Health = 0을 보면 캐릭터의 생명력이 0이 된다 -> 죽는다는 것을 알 수 있다.

 

아래는 캐릭터가 죽으면 되살아나는 리스폰 지점을 정하는 스크립트

local spawn = script.Parent
spawn.Touched:connect(function(hit)
	if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		local checkpointData = game.ServerStorage:FindFirstChild("CheckpointData")
		if not checkpointData then
			checkpointData = Instance.new("Model", game.ServerStorage)
			checkpointData.Name = "CheckpointData"
		end
		
		local checkpoint = checkpointData:FindFirstChild(tostring(player.userId))
		if not checkpoint then
			checkpoint = Instance.new("ObjectValue", checkpointData)
			checkpoint.Name = tostring(player.userId)
			
			player.CharacterAdded:connect(function(character)
				wait()
				character:WaitForChild("HumanoidRootPart").CFrame = game.ServerStorage.CheckpointData[tostring(player.userId)].Value.CFrame + Vector3.new(0, 4, 0)
			end)
		end
		
		checkpoint.Value = spawn
	end
end)

 

728x90