Modular Platforms in Unity

Objective: Create modular platforms with working ledge grab.

The Platform Ledge in the fore ground was created from a prefab of the one in the background.

To convert the ledge grab system to a modular design, create two empty game objects, labeled _pointHanging and _pointStand.

Adjust the position is of these game objects and child these to the ledge, in this case Scifi_Floors_Edge(4) which is a child of Platform_Ledge. Their relative position on the ledge can be seen below.

The LedgeChecker script on Ledge_Checker is modified as show by the green bars before the lines of code below. Two variables are created to store these points, _hangingPoint and _pointStand. The transform.positions for these points are passed to the Player script via its public LedgeGrab method.

LedgeChecker script on Ledge_Checker.

Both _hangingPoint and _pointStand are assigned in the Inspector for Ledge_Checker as shown below.

Assignment of variables to the LedgeChecker script.

Check to make sure the ledge system is working then drag the whole Platform_Ledge into the Prefabs folder in the Assets folder for the project. This new prefab can now be added to the scene again and the ledge system works without any modification of the new ledge. Because these points are children of the Platform_Ledge, when the ledge is moved the spacing for the ledge jump detection is also kept. Each ledge passes its own coordinates to Player providing the ability to climb each individual ledge in this modular design.

Software engineer