본문 바로가기
공허의 유산/표현의 자유

[아빠의 Roblox 숙제]#1. 와리가리 물체를 이용해서 건너가기

by 바른생활머시마 2021. 1. 29.
728x90
반응형

둘째 아이가 만들고 싶어한 맵이 '길건너 친구들'처럼 이동하는 물체를 딛고 건너가는 형식의 점프맵이었습니다.

이동하는 물체는 스크립트로 위치를 조정해주면 쉽게 되는데, 그 위에 탈 수 있게 하는 것은 조금 더 복잡하더라구요.

CFrame이 핵심이었던 것 같기도 하고~~~

 

길 건너 친구들처럼 공중에서 떨어지지 않고 건너가는 맵을 만들 때 사용 할 수 있는 모듈을 만들어 봤어요.

여러가지 방식이 있는 것 같은데, 참고 한 방식은 두 개의 파트 사이에서 충돌하면 방향을 변경 해 주는 방식입니다. 

두 개의 파트가 있어야 한다는 제약이 있지만, 달리 말하면 두 개의 파트 위치를 조정하면 직관적으로 수정이 용이하죠.

코드는 아래와 같습니다. 아직 초보라서 좀 이해 안되는 부분이 있긴한데, 언제고 이해 될 날이 오겠죵~

local SPEED = 10;
local start = script.Parent:WaitForChild("start");
local finish= script.Parent:WaitForChild("finish");

local attach0 = Instance.new("Attachment");
attach0.CFrame = CFrame.new();
attach0.Parent = script.Parent;

local attach1 = Instance.new("Attachment");
attach1.CFrame = finish.CFrame;
attach1.Parent = game.Workspace.Terrain;

local pris = Instance.new("PrismaticConstraint");
pris.ActuatorType = Enum.ActuatorType.Motor;
pris.MotorMaxForce = math.huge;
pris.Attachment0 = attach1;
pris.Attachment1 = attach0;
pris.Parent = script.Parent;

local foward = true;
pris.Velocity = SPEED;
attach1.CFrame = finish.CFrame

start.Touched:Connect(function(hit)
	if (hit == script.Parent and not foward)then
		foward = true;
		pris.Velocity = SPEED;
		attach1.CFrame = finish.CFrame
	end
end)

finish.Touched:Connect(function(hit)
	if (hit == script.Parent and foward)then
		foward = false;
		pris.Velocity = -SPEED;
		attach1.CFrame = start.CFrame
	end
end)


 

 

 

아래와 같이 올라타서 움직일 수 있으며, 중간에 끼면 의도하지 않은 몸개그도.....

 

 

 

 

 

저장소 : github.com/red112/roblox/tree/main/0001_movingobj

참고자료 : youtu.be/PK4Ed6hm4Io

 

728x90
반응형

댓글