반응형

스폰로케이션

탐색기 - StarterPlayerScripts - Local Script 3개 추가 

DoubleJump, ControlScript, CameraScript

컨트롤 스크립트
local player = game.Players.LocalPlayer
local UserInputService = game:GetService("UserInputService")
local ContextActionService = game:GetService("ContextActionService")

local doJump = false
local reviving = false
local characterWalkSpeed = 40

game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Chat, false)
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Health, false)
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)

local function jump()
	if player.Character ~= nil then
		if player.Character.Humanoid.WalkSpeed == 0 then
			-- Character is not yet moving, start screen was shown
			doJump = false
			if player.PlayerGui.StartScreen.StartInstructions.Visible == true then
				player.PlayerGui.StartScreen:Destroy()
				player.Character.Humanoid.WalkSpeed = characterWalkSpeed
				game.ReplicatedStorage.RemoteEvents.RunStarting:FireServer()
			end
		else
			player.Character.Humanoid.Jump = true
		end
	end
end

if UserInputService.TouchEnabled then
	UserInputService.ModalEnabled = true
	UserInputService.TouchStarted:connect(function(inputObject, gameProcessedEvent) if gameProcessedEvent == false then doJump = true end end)
	UserInputService.TouchEnded:connect(function() doJump = false end)
else
	ContextActionService:BindAction("Jump", function(action, userInputState, inputObject) doJump = (userInputState == Enum.UserInputState.Begin) end, false, Enum.KeyCode.Space, Enum.KeyCode.ButtonA)
end

game:GetService("RunService").RenderStepped:connect(function()
	if player.Character ~= nil then
		if player.Character:FindFirstChild("Humanoid") then
			if doJump == true then
				jump()
			end
			player.Character.Humanoid:Move(Vector3.new(0,0,-1), false)
		end
	end
end)
카메라 스크립트
local camera = game.Workspace.CurrentCamera
local player = game.Players.LocalPlayer

camera.CameraType = Enum.CameraType.Scriptable

local targetDistance = 30
local cameraDistance = -30
local cameraDirection = Vector3.new(-1,0,0)

local currentTarget = cameraDirection*targetDistance
local currentPosition = cameraDirection*cameraDistance

game:GetService("RunService").RenderStepped:connect(function()
	local character = player.Character
	if character and character:FindFirstChild("Humanoid") and character:FindFirstChild("HumanoidRootPart") then
		local torso = character.HumanoidRootPart
		camera.Focus = torso.CFrame
		if torso:FindFirstChild("FastStart") == nil then
			camera.CoordinateFrame = 	CFrame.new(Vector3.new(torso.Position.X, torso.Position.Y + 10, torso.Position.Z - 20) + currentPosition, 
				Vector3.new(torso.Position.X,  torso.Position.Y, torso.Position.Z - 20) + currentTarget)
		else
			--Lower camera for fast start
			camera.CoordinateFrame = CFrame.new(Vector3.new(torso.Position.X, torso.Position.Y - 15, torso.Position.Z - 20) + currentPosition, 
				Vector3.new(torso.Position.X,  torso.Position.Y - 15, torso.Position.Z - 20) + currentTarget)
		end
	end
end)
보상추가하기

코인 소리 바꾸기

local db = true
script.Parent.Touched:connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") ~= nil then
		if db == true then
			db = false
			script.Parent.Transparency = 1
			local player = game.Players:GetPlayerFromCharacter(hit.Parent)
			player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 1
			script.Sound:Play()
			script.Parent.Transparency = 1
			wait(1)
			db = true
			script.Parent.Transparency = 0 
		end
	end	
end)

획득 후 사라지게 만들기 위해서는 

local db = true
script.Parent.Touched:connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") ~= nil then
		if db == true then
			db = false
			script.Parent.Transparency = 1
			local player = game.Players:GetPlayerFromCharacter(hit.Parent)
			player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 1
			script.Sound:Play()
			script.Parent.Transparency = 1
			wait(1)
			--db = true
			script.Parent.Transparency = 0 -- 투명 속성 값을 0으로 바꿔준다
		end
	end	
end)
배경넣기

점프 아이템 추가

이단점프 
--여기가 첫번째 줄
local UserInputService = game:GetService("UserInputService") -- 키보드 인식을 위해(13번째 줄)
local localPlayer = game.Players.LocalPlayer -- 플레이어 구해줌
local character -- 캐릭터를 담기위한 변수(28줄)
local humanoid -- 휴머노이드를 담기 위한 변수(29줄)
print("jumpscriptloaded")
local canDoubleJump = false -- 이단점프가능한가?(제어)
local hasDoubleJumped = false -- 이단점프를 했는가?
local oldPower -- 원래점프력담기위한 변수(32줄)
local TIME_BETWEEN_JUMPS = 0.2 -- 점프하고 두번재 할때까지의 시간차
local DOUBLE_JUMP_POWER_MULTIPLIER = 2 -- 두번째 점프할때 원래점프력보다 몇배 더 강하게 하는가?

UserInputService.JumpRequest:connect(function() -- 점프요청을 함수로 받음
	if not character or not humanoid or not character:IsDescendantOf(workspace) or 
		humanoid:GetState() == Enum.HumanoidStateType.Dead then
		--캐릭터가 없거나, 휴머노이드가 없거나, 캐릭터가 workspace에 없거나, 캐릭터가 죽어있으면,
		return -- 함수 취소
	end

	if canDoubleJump and not hasDoubleJumped then -- 이단점프가능한가? 가 참이고, 이단점프했는가? 가 참이 아닌경우,
		hasDoubleJumped = true -- 더블점프한 상태라고 표시해줌
		humanoid.JumpPower = oldPower * DOUBLE_JUMP_POWER_MULTIPLIER -- 캐릭터 휴머노이드에서 점프력 설정해줌
		humanoid:ChangeState(Enum.HumanoidStateType.Jumping) -- 캐릭터 점프
	end
end)

local function characterAdded(newCharacter) --47줄이나 50줄에서 오는 함수
	character = newCharacter -- 캐릭터 구해줌
	humanoid = newCharacter:WaitForChild("Humanoid") -- 캐릭터 휴머노이드 구해줌
	hasDoubleJumped = false  --이단점프했는가? 거짓으로 설정
	canDoubleJump = false -- 이단점프가능한가? 거짓으로 설정
	oldPower = humanoid.JumpPower -- 원래 점프력 저장

	humanoid.StateChanged:connect(function(old, new) -- 휴머노이드 상태가 바뀔 때 함수 발동, 입력변수(전상태, 현재상태)
		if new == Enum.HumanoidStateType.Landed then -- 착지상태인경우
			canDoubleJump = false -- 이단점프가능한가? 거짓으로 설정
			hasDoubleJumped = false --이단점프했는가? 거짓으로 설정
			humanoid.JumpPower = oldPower -- 점프력되돌림(22줄에서 바꿈)
		elseif new == Enum.HumanoidStateType.Freefall then -- 떨어지는 상태인경우
			wait(TIME_BETWEEN_JUMPS) -- 10줄에서 정해준것만큼 기다림
			canDoubleJump = true -- 이단점프가능한가? 참으로 설정
		end
	end)
end

if localPlayer.Character then --캐릭터가 이미 있는 경우
	characterAdded(localPlayer.Character) -- 27줄 함수로 연결
end

localPlayer.CharacterAdded:connect(characterAdded) --캐릭터 스폰된경우 27줄 함수로 연결

 

반응형
반응형

 

변수는 프로그래밍을 할 때 컴퓨터 메모리(Memory)에 여러 데이터를 저장해 놓는 공간입니다. 보통 바구니와 상자 그릇으로 비유하곤 합니다. 저장하는 데이터의 종류에는 숫자형(Number), 문자형(String), 논리형(Boolean)이 있습니다.

 

▶ 변수 만들기

 

변수는 아래와 같이 (변수명) = (들어갈 데이터) 의 형식으로 만들수 있습니다. 오른쪽의 (들어갈 데이터)가 왼쪽 (변수명)의 이름을 가진 그릇에 담긴다고 생각하면 이해하기 쉬울 것입니다.

txt = "Hello World!" 
number = 1234
isActive = true

txt 변수에는 문자형 데이터 "Hello World!"가 저장되며 시작과 끝을 큰따옴표(" ")로 감싸줘야합니다. number 변수에는 숫자형 데이터 1234가 저장되며 isActive에는 논리형 데이터 True가 저장됩니다.  

 

이러한 변수는 코드 전체에서 사용이 가능한 전역 변수(Global Variable)와 일정 스크립트와 같은 함수에서만 사용이 가능한 지역 변수(Local Variable)로 나눌 수 있습니다.  전역변수와 지역변수에 자세한 설명은 포스팅을 진행하면서 좀 더 자세히 설명하겠습니다. 

 

 예약어

아래의 키워드들은 이미 프로그래밍할 때 사용하기 위해 미리 예약되어있기 때문에 변수, 상수, 등 여타 식별자의 이름으로 사용할 수 없습니다.

true false and or local
if else elseif for end
nil not function repeat while
local in then do return
until        

 

 

 스크립트 작성하기

[모델] 탭을 클릭하고 오른쪽 끝에 있는 Script아이콘을 클릭한다. 그 후 나타나는 Script 창에 아래와 같이 작성해본다.

txt = "Hello World!" 
number = 1234
isActive = true

print(txt)
print(number)
print(isActive)

 변수 출력하기

[스크립트 메뉴] 탭의 플레이를 클릭하여 실행할 수 있다. 플레이 버튼의 아래쪽 화살표를 눌러보면 플레이(F5) / 실행(F8)이 있다. 단순히 스크립트를 실행 할 때에는 실행 (F8)로 플레이하는것을 추천한다. 

 

 결과확인하기

[보기]탭에서 출력 창이 켜져있는지 확인해보고 켜져있지 않다면 켜준다.

실행(F8)을 눌러 실행해보면 출력창에 우리가 작성한 스크립트가 출력되는 것을 확인할 수 있다.

2021.09.03 - [분류 전체보기] - [Roblox Studio] 로블록스 스튜디오 - 설치 및 기본

 

 

 

[Roblox Studio] 로블록스 스튜디오 - 설치 및 기본

로블록스(Roblox)는 자체 게임엔진인 로블록스 스튜디오를 통해 스스로 게임을 만들거나 다른 사람이 만든 게임을 즐길 수 있다. 즉 누구나 게임을 만들고 즐길 수 있다. 로블록스에는 사용자들이

betterthan2020.tistory.com

 

반응형
반응형

로블록스(Roblox)는 자체 게임엔진인 로블록스 스튜디오를 통해

스스로 게임을 만들거나 다른 사람이 만든 게임을 즐길 수 있다. 

 

 

 

즉 누구나 게임을 만들고 즐길 수 있다. 

로블록스에는 사용자들이 만든 다양한 장르의 게임이 있는데

인기있는 게임은 1000만명의 플레이어를 보유하고 있다.

 

 

 

Roblox Studio

 

 

Create - Roblox

Create anything you can imagine with Roblox's free and immersive creation engine. Start creating experiences today!

www.roblox.com

 

 

 

로블록스 스튜디오는  

개발 프로그래밍 언어로 루아(Lua) 5.1.4 를 지원한다.

루아는 작고 가벼운 스크립팅 언어이지만 확장성이 뛰어난 언어로 많은 사랑을 받고 있다.

 

 

 

 

 

 

 

 

한창 게임을 즐기고 관심이 많은 학생들에게

게임을 즐기기만 하는게 아니라 직접 제작해보면서

게임제작자로서의 진로 탐색도 해볼 수 있다.

 

기본적인 설치 방법 포스팅을 시작으로 로블록스 기본 사용법과 Lua 언어를 함께 배워보도록 하겠다. 

 

▶ 다운로드 

[만들기 Create]  탭을 클릭하면 다음과 같은 화면이 나타난다. 가운데 [Studio 다운로드]를 클릭하면 사용하는 운영체제에 맞는 로블록스 스튜디오가 설치된다. 

로블록스 스튜디오 설치파일을 다운로드 후 설치 및 실행하면 로그인 창이 나타난다.

로그인 화면 

▶ Templet  템플릿

[New +  → All Templets]  탭을 클릭하면 다음과 같은 화면이 나타난다.  다양한 기본 템플릿을 선택할 수 있는데 두번째  [Classic Baseplate ]를 클릭해보자.

▶ 기본 메뉴

첫 화면은 기본 메뉴  [HOME, MODEL, TEST, VIEW, PLUGINS]    [HOME] 화면이  나타난다. 

 

▶ VIEW 

[VIEW] 탭을 선택해서 

Explorer, Properties, Output, Command Bar 를 눌러서 창을 활성화 해준다.

 

 

 

 

 

 

▶ MODEL 

[MODEL] 탭을 선택 후 스크립트 아이콘을 눌러 

스크립트 창을 활성화 해준다. 

스크립트 창을 살펴보면 Hello World 가 기본적으로 입력되어 있다. 

 

 

print("Hello World")

 

 

Classic Baseplate , Script 를 클릭하면서 게임화면과 스크립트 화면을 전환할 수 있다. 

 

▶ SCRIPT MENU - RUN

[SCRIPT MENU] 탭을 선택 후 RUN 아이콘을 눌러 스크립트를 실행할 수 있다.

[Play F5] 와  [Run F8] 을 클릭하여 스크립트를 실행할 수 있는데 [Play F5] 는 게임이 실행되며 [Run F8]은 스크립트가 실행된다. 스크립트의 실행결과는 Output 창에서 확인 할 수 있다.

Hello world!

다음 시간부터는 본격적으로 로블록스 스튜디오의 사용법과  Lua 언어 문법을 본격적으로 배워보도록 하겠다. 

 

 

 

 

 

반응형

+ Recent posts