Creating A Trap
Vérifié avec version: 2018.1
Using the Game Commands we will rotate an object when receiving a Game Command to drop a box on some Spitters.
Create a new Empty GameObject in the Hierarchy under the Gameplay group
Name it PlatformTrap
Move the Location of PlatformTrap to wherever you wish to rotate the platform. This will be used as a pivot point to rotate the Platforms.
Transforming it now means we attach the other GameObjects in the next steps, rotating them around its location as opposed to their current location.
- Drag in a PlatformShort from 3DGamekit > Prefabs > Environment > Stonework into the Hierarchy and Transform its position to be near the pivot PlatformTrap
Do the same steps for a PlatformSupportShort Prefab from the same folder transforming it underneath the Platform.
In the Hierarchy select both the PlatformShort and PlatformSupportShort
Disable the Static parameter in Inspector. This will allow the GameObjects to move when the parent rotates.
- With both still selected in the Hierarchy, drag them onto the PlatformTrap Empty GameObject, making it look like the following
Tip: It should be surrounded by a blue bubble to add them
Select the parent PlatformTrap
- In the Inspector Add Components for Game Command Receiver and a Simple Rotator.
This will allow the Parent group, PlatformTrap, to receive Game Commands and rotate the child objects without separate setup.
Let's change some of the settings in the SimpleRotator component to make the rotation more believable.
Change the following settings:
Interaction Type : Activate
Is One Shot : Checked
Accel Curve : Linear Increase (Click in the box and select the 2nd default line)
Loop Type : Once
Axis Z : 1
End Angle : -60
If you move the slider on the Preview Position you should see the PlatformTrap rotate similar to a trap door.
Tip: If it does not perform as expected or rotates strangely from what you expect, take the PlatformShort and PlatformSupportShort out of the PlatformTrap group in Hierarchy, move the PlatformTrap to where you need to pivot and then add the Platform and Support back into the group.
Similar to the MovingPlatform tutorial let’s use a pressure pad to activate the rotation on the PlatformTrap.
- Drag a PressurePad from Prefabs > Interactables to somewhere in your scene near the PlatformTrap
With the PressurePad selected, drag the PlatformTrap group from Hierarchy into the Send On Trigger Enter Interactive Object for the Game Command Receiver.
Change Interaction Type to Activate
A visual link should show with a direction of Send and Receive
- Play the scene at this point the pad will activate the rotation.
To damage the Spitters, add a DestructibleBox from 3DGamekit > Prefabs > Interactables by dragging the prefab into the scene and transforming it into position, sat atop the PlatformTrap.
In the Hierarchy, expand the DestructibleBox group and select the DestructibleBox child GameObject.
- In the Inspector, add a Component for Contact Damager and set the Damaged Layers to Enemy
The Amount value should match that of the Max Hit Points found in Damageable component of the enemies.
- Play the scene and activate the trap to see the box hit enemies below.