Infinite Path game using Unity3d
Objective: The main objective of the game is to implement an infinitely generating linear track/maze and develop a rolling ball game using Unity3d.
Game Play:
The player in this game is a sphere which can be moved in the game using the arrow keys. The ball cannot move backward. The Green and Red cubes act as obstacles to the game. The Red obstacles move horizontally in the track and whenever the player collides with the Red moving Obstacles, you lose control over the player and the game ends.
The track looks like a finite length track but its length increases at runtime, making it an infinite length track. The distance on the plane travelled by the player is displayed as score in the game.
Implementation
1. Infinite Track:
The infinite track is implemented using prefabs and instantiate function. We have created three prefabs for the tracks for track0, track1 and track2. All the three tracks are placed one after the other initially. As the ball reaches the edge of the track0, instantiate function is called and one of the three tracks is selected randomly and is appended at the edge of the track2 with the same orientation. Similarly as the ball reaches the edge of track1, instantiate is called again and the track is appended with one of the three tracks. As the game progresses, the track is generated at run time.
2. Player Movement:
The Player moves as we press the arrow keys, but the backward movement of the player is restricted. Once the player move forward on the track, you cannot move the player in backward (-z) direction. To implement this, the force is made to apply only when the movement is in +z and force is not applied when the movement is in -z direction.
3. Moving Obstacles:
The red obstacles placed in the track, moves horizontally across the length of the track. PingPong function is used for this purpose and the movement is multiplied by Time.deltaTime to make the movement consistent with the frame. OnTriggerEnter (Collider Other) is used to detect the collisions of the player with the red obstacles and the game over is displayed.
4. Game Over:
As the player collides with the Red obstacle, the game over message is displayed using "gameoverText.text" and you lose control over the player i.e., you can’t move the player using arrow keys anymore.
5. The GameObjects are colored using "gameObject.renderer.material.color".
Future enhancements – thoughts:
- Timer
- Replacing the sphere with an animated avatar.
- Including pits and valleys in the track like temple run (may be)
- Adding the jump movement to the player object.
- Adding animated explosions when the player object collides with the red obstacles.
- More camera views.
- Adding Terrain and scenes.
No comments:
Post a Comment