Collision

์›”๋“œ ๊ฐ์ฒด์— ๋Œ€ํ•ด ์ถฉ๋Œ ๊ด€๋ จ ์„ค์ •์„ ์ฒ˜๋ฆฌํ•˜๋Š” ๊ฐ์ฒด์—์š”.

์ด๋ฒคํŠธ

OnCollisionEvent

๋‹ค๋ฅธ ๊ฐ์ฒด์™€ ์ถฉ๋Œํ•  ๋•Œ ํ˜ธ์ถœ๋˜๋Š” ์ด๋ฒคํŠธ์—์š”. ์—ฐ๊ฒฐํ•จ์ˆ˜ ํ˜•์‹์€ function(self, target), self ๋Š” ์ด๋ฒคํŠธ๋ฅผ ์—ฐ๊ฒฐํ•œ ์˜ค๋ธŒ์ ํŠธ, target ์€ self ์™€ ์ถฉ๋Œํ•œ ์˜ค๋ธŒ์ ํŠธ ์ž…๋‹ˆ๋‹ค.

-- ์ƒ˜ํ”Œ --

local cube = Workspace.Cube

local function CollisionEvent(self, target) --OnCollisionEvent๋กœ ์—ฐ๊ฒฐ๋œ ํ•จ์ˆ˜๋Š” self์™€ target ์ธ์ž๊ฐ€ ๊ณ ์ •์ ์œผ๋กœ ๋“ค์–ด๊ฐ€์š”.
    if target ~= nil then
        print("CollisionEvent " .. target.Name)
    end
end
cube.Collision.OnCollisionEvent:Connect(CollisionEvent) --Collision์ด true์ธ ์˜ค๋ธŒ์ ํŠธ์™€ ์ถฉ๋Œ์ค‘์ผ๋•Œ ํ˜ธ์ถœ๋˜๋Š” ํ•จ์ˆ˜๋ฅผ ์—ฐ๊ฒฐํ•ด์š”.

OnBeginOverlapEvent

๋‹ค๋ฅธ ๊ฐ์ฒด์™€ ๊ฒน์ณ์งˆ ๋•Œ ํ˜ธ์ถœ๋˜๋Š” ์ด๋ฒคํŠธ์—์š”. ์—ฐ๊ฒฐํ•จ์ˆ˜ ํ˜•์‹์€ function(self, target), self ๋Š” ์ด๋ฒคํŠธ๋ฅผ ์—ฐ๊ฒฐํ•œ ์˜ค๋ธŒ์ ํŠธ, target ์€ self ์™€ ๊ฒน์นœ ์˜ค๋ธŒ์ ํŠธ ์ž…๋‹ˆ๋‹ค.

-- ์ƒ˜ํ”Œ --

local cube = Workspace.Cube

local function BeginOverlapEvent(self, target) --OnBeginOverlapEvent ์—ฐ๊ฒฐ๋œ ํ•จ์ˆ˜๋Š” self์™€ target ์ธ์ž๊ฐ€ ๊ณ ์ •์ ์œผ๋กœ ๋“ค์–ด๊ฐ€์š”.
    if target ~= nil then
        print("BeginOverlapEvent " .. target.Name)
    end
end
cube.Collision.OnBeginOverlapEvent:Connect(BeginOverlapEvent) --Collision์ด false์ธ ์˜ค๋ธŒ์ ํŠธ์™€ ์ถฉ๋Œ์„ ์‹œ์ž‘ํ• ๋•Œ ํ˜ธ์ถœ๋˜๋Š” ํ•จ์ˆ˜๋ฅผ ์—ฐ๊ฒฐํ•ด์š”.

OnEndOverlapEvent

๋‹ค๋ฅธ ๊ฐ์ฒด์™€ ๊ฒน์ณ์ง์ด ๋๋‚  ๋•Œ ํ˜ธ์ถœ๋˜๋Š” ์ด๋ฒคํŠธ์—์š”. ์—ฐ๊ฒฐํ•จ์ˆ˜ ํ˜•์‹์€ function(self, target), self ๋Š” ์ด๋ฒคํŠธ๋ฅผ ์—ฐ๊ฒฐํ•œ ์˜ค๋ธŒ์ ํŠธ, target ์€ self ์™€ ๊ฒน์นจ์ด ๋๋‚œ ์˜ค๋ธŒ์ ํŠธ ์ž…๋‹ˆ๋‹ค.

-- ์ƒ˜ํ”Œ --

local cube = Workspace.Cube

local function EndOverlapEvent(self, target) --OnEndOverlapEvent ์—ฐ๊ฒฐ๋œ ํ•จ์ˆ˜๋Š” self์™€ target ์ธ์ž๊ฐ€ ๊ณ ์ •์ ์œผ๋กœ ๋“ค์–ด๊ฐ€์š”.
    if target ~= nil then
        print("EndOverlapEvent " .. target.Name)
    end
end
cube.Collision.OnEndOverlapEvent:Connect(EndOverlapEvent) --Collision์ด false์ธ ์˜ค๋ธŒ์ ํŠธ์™€ ์ถฉ๋Œ์ด ๋๋‚ ๋•Œ ํ˜ธ์ถœ๋˜๋Š” ํ•จ์ˆ˜๋ฅผ ์—ฐ๊ฒฐํ•ด์š”.

OnOverlapUpdateEvent

๋‹ค๋ฅธ ๊ฐ์ฒด์™€ ๊ฒน์ณ์žˆ๋Š” ๋™์•ˆ ๋งค ํ”„๋ ˆ์ž„๋งˆ๋‹ค ํ˜ธ์ถœ๋˜๋Š” ์ด๋ฒคํŠธ์—์š”. ์—ฐ๊ฒฐํ•จ์ˆ˜ ํ˜•์‹์€ function(self, target), self ๋Š” ์ด๋ฒคํŠธ๋ฅผ ์—ฐ๊ฒฐํ•œ ์˜ค๋ธŒ์ ํŠธ, target ์€ self ์™€ ๊ฒน์ณ์žˆ๋Š” ์˜ค๋ธŒ์ ํŠธ ์ž…๋‹ˆ๋‹ค.

-- ์ƒ˜ํ”Œ --

local cube = Workspace.Cube

local function OverlapUpdateEvent(self, target, updateTime) --OnOverlapUpdateEvent๋กœ ์—ฐ๊ฒฐ๋œ ํ•จ์ˆ˜๋Š” self, target, updateTime ์ธ์ž๊ฐ€ ๊ณ ์ •์ ์œผ๋กœ ๋“ค์–ด๊ฐ€์š”.
    if target ~= nil then
        print("OverlapUpdateEvent " .. target.Name)
    end
end
cube.Collision.OnOverlapUpdateEvent:Connect(OverlapUpdateEvent) --Collision์ด false์ธ ์˜ค๋ธŒ์ ํŠธ์™€ ์ถฉ๋Œ์ค‘์ผ๋•Œ ํ˜ธ์ถœ๋˜๋Š” ํ•จ์ˆ˜๋ฅผ ์—ฐ๊ฒฐํ•ด์š”.

ํ•จ์ˆ˜

void SetCollisionType(string usercollisiontype)

ํ•ด๋‹น ์˜ค๋ธŒ์ ํŠธ์˜ ์ถฉ๋Œ ํƒ€์ž…์„ ์ง€์ •ํ•ด์ค˜์š”.

-- ์ƒ˜ํ”Œ --

Game:AddUserCollisionType("CollisionTag1") --๊ฒŒ์ž„์— ์œ ์ € ์ถฉ๋Œ ํƒ€์ž…(CollisionTag1)์„ ์ถ”๊ฐ€ํ•ด์š”.

local cube1 = Workspace.Cube1
local cube2 = Workspace.Cube2

cube1.Collision:SetCollisionType("CollisionTag1") --๊ฐ์ฒดA์— ์ถฉ๋Œ ํƒ€์ž…(CollisionTag1)์„ ์„ค์ •ํ•ด์š”.

cube2.Collision:SetUserCollisionTypeResponse("CollisionTag1", Enum.CollisionResponse.Overlap) --๋˜ ๋‹ค๋ฅธ ๊ฐ์ฒดB์— ์ถฉ๋Œ ํƒ€์ž…(CollisionTag1)๋ณ„ ์ถฉ๋Œ ๋ฐ˜์‘์„ ์„ค์ •ํ•ด์š”.

String GetCollisionType()

ํ•ด๋‹น ์˜ค๋ธŒ์ ํŠธ์˜ ์ถฉ๋Œ ํƒ€์ž…์„ ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์žˆ์–ด์š”.

-- ์ƒ˜ํ”Œ --

local cube = Workspace.Cube

print(cube.Collision:GetCollisionType()) --ํ•ด๋‹น ์˜ค๋ธŒ์ ํŠธ์˜ ์ถฉ๋Œ ํƒ€์ž…์„ ๊ฐ€์ ธ์™€์š”.

void SetCharacterCollisionResponse(CollisionResponse CollisionResponse)

์บ๋ฆญํ„ฐ์™€ ์ถฉ๋Œ ์‹œ ์–ด๋–ป๊ฒŒ ์ฒ˜๋ฆฌ ํ• ์ง€๋ฅผ ์„ค์ •ํ•˜๋Š” ํ•จ์ˆ˜์—์š”. ( Enum.CollisionResponse.ํƒ€์ž… )

-- ์ƒ˜ํ”Œ --

Workspace.Cube1.Collision:SetCharacterCollisionResponse(Enum.CollisionResponse.Block) --์˜ค๋ธŒ์ ํŠธ๊ฐ€ ์บ๋ฆญํ„ฐ์™€ ์ถฉ๋Œํ–ˆ์„๋•Œ ํ†ต๊ณผ๋˜์ง€ ์•Š๊ณ  ์—ฐ๊ฒฐ๋œ ์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒ๋˜๊ฒŒ ์„ค์ •ํ•ด์š”.
Workspace.Cube2.Collision:SetCharacterCollisionResponse(Enum.CollisionResponse.Overlap) --์˜ค๋ธŒ์ ํŠธ๊ฐ€ ์บ๋ฆญํ„ฐ์™€ ์ถฉ๋Œํ–ˆ์„๋•Œ ํ†ต๊ณผ๋˜๊ณ  ์—ฐ๊ฒฐ๋œ ์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒ๋˜๊ฒŒ ์„ค์ •ํ•ด์š”..
Workspace.Cube3.Collision:SetCharacterCollisionResponse(Enum.CollisionResponse.Ignore) --์˜ค๋ธŒ์ ํŠธ๊ฐ€ ์บ๋ฆญํ„ฐ์™€ ์ถฉ๋Œํ–ˆ์„๋•Œ ํ†ต๊ณผ๋˜๊ณ  ์—ฐ๊ฒฐ๋œ ์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒ๋˜์ง€ ์•Š๊ฒŒ ์„ค์ •ํ•ด์š”.

void SetUserCollisionTypeResponse(string UserCollisionType, CollisionResponse CollisionResponse)

์œ ์ €ํƒ€์ž… ์ถฉ๋Œ ๋ฌผ์ฒด์˜ ์ถฉ๋Œ ์‹œ ์ฒ˜๋ฆฌ๋ฅผ ๋ณ€๊ฒฝํ•˜๋Š” ํ•จ์ˆ˜์—์š”. (๋ณ€๊ฒฝ ํ•  ์œ ์ €ํƒ€์ž… ์ถฉ๋Œ ์ด๋ฆ„, Enum.CollisionResponse.ํƒ€์ž… )

-- ์ƒ˜ํ”Œ --

Game:AddUserCollisionType("CollisionTag1") --๊ฒŒ์ž„์— ์œ ์ € ์ถฉ๋Œ ํƒ€์ž…(CollisionTag1)์„ ์ถ”๊ฐ€ํ•ด์š”.

local cube1 = Workspace.Cube1
local cube2 = Workspace.Cube2

cube1.Collision:SetCollisionType("CollisionTag1") --๊ฐ์ฒดA์— ์ถฉ๋Œ ํƒ€์ž…(CollisionTag1)์„ ์„ค์ •ํ•ด์š”.

cube2.Collision:SetUserCollisionTypeResponse("CollisionTag1", Enum.CollisionResponse.Overlap) --๋˜ ๋‹ค๋ฅธ ๊ฐ์ฒดB์— ์ถฉ๋Œ ํƒ€์ž…(CollisionTag1)๋ณ„ ์ถฉ๋Œ ๋ฐ˜์‘์„ ์„ค์ •ํ•ด์š”.

Last updated