-
Notifications
You must be signed in to change notification settings - Fork 0
Obstacles
In the game, an obstacle, as it's name describe, represents a form of GameObject that stops the player's movement to a given direction.
As an example, an obstacle can be a piece of ground and path on which the player's actor runs; prevents the actor from falling down by the force of physics. An obstacle can also be an elevation that forces the player to jump it.
Levels contain sets of obstacles that are loaded dynamically on the scene's awakening using Unity's Resources.Load() functionality. Obstacles are stored in form of prefabs under a specific path in the Assets / Resources folder:
[Folder] Resources
- [Sub Folder] Level{id}
- - [Sub Folder] Obstacles
Where the Level{id} folder, sub folder of Resources, represents the name of the level in which level related game objects are placed, and where the Obstacles folder, sub folder of Level{id}, represents the final folder in which obstacle prefabs are placed.
You must replace {id} in Level{id} with the unique integer identification for your level. For example Level1. The initial level id is set in the game manager's inspector (Manager) to indicate with which level to start the game; on a level change, this value will increase by 1 and the manager will look and load the resources placed for the next level.
The following requirements or checklist are important in order to make functional an obstacle game object, if these are not respected, the obstacle may not work during gameplay:
-
Obstacle Component: The root game object must have attached the
Obstacle Componentin order for theManagerto recognize it. -
Obstacle Tag: Any root or child game object with a
Collider Component, non-trigger, must be tagged with theObstacle Tagin order to make it recognizable in collisions. -
Add Rigidbodies: Any collider, non-trigger, in the obstacle game object must have a
Rigidbody Componentattach to it, since this object will move. -
Is Kinematic ON: Obstacles are moved by script (job done by the
Manager), so turn on theIsKinematicproperty in theRigidbody Component, this will prevent useless calls to the Unity's physics engine. -
Freeze constraints: Freeze all position and rotation constraint properties in the
Rigidbody Componentto prevent obstacle unwanted movements by physics. -
NoFriction material: (OPTIONAL) Add the
NoFriction Physics Materialto the all non-trigger colliders, this will prevent unwanted behaviors of players in cliffs and elevations.
Be aware that an obstacle can be a lonely game object or a parent game object with different child game objects. The Obstacle Component will detect all child game object on Awake in order to determine it's true bounds.
Advise: Review the above checklist on each child game object to verify that it is valid.
You can include specific triggers in the obstacle in order to add/subtract score or to cause a specific effect on the player.
In order to do this, add a trigger Collider Component and an Obstacle Trigger Component to the related obstacle. Set the points to be added or subtracted from the score when the collider is triggered by the player and the speed effect.