Ropes' Adventure
Duration: 7 Weeks
Engine: Unity
Platform: PC
Responsibilites: Scripter/AI Programmer
Genre: Singleplayer,Adventure,Platformer
Language: C#


Ropes' Adventure is a 3rd person adventure-platformer where you play as ropes a young red panda that explores the Monkey Temple in search for his lost grandfather. The game was developed by nine students as a school project where my role was AI Programmer & scripte


Overview

The turtles in rope's adventure worked as collectables in the game we had both baby turtles that the player has to adventure around the world to find and collect. While the mother turtle was on set location in world and you picked up a baby turtle they would appear following the mother.


Mother Turtle

When i created the mother turtle i wanted her to walk to random position inside a preset zone. The way i did this was i created a sphere that worked as a zone. I attached this to the mothers prefab so the workflow wouldn't get affected and since i didn't want the zone to move with the ai i detached the sphere on start of the game so the mother would only walk inside a radius from where she was placed.

Click Code to Expand

1using UnityEngine;
2using System.Collections;
3using System.Collections.Generic;
4
5public class Mothership : MonoBehaviour
6{
7 // Public
8 [HideInInspector]
9 public NavMeshAgent meshAgent;
10
11 // Private
12 GameObject SphereRadius;
13 SphereCollider WalkRadius;
14 Animator animator;
15 DestTrigger TriggerDest;
16 Transform triggerTransform;
17 Vector3 Destination;
18 Vector3 lastpos = Vector3.zero;
19
20 bool hasDestination = false;
21
22 void Start()
23 {
24 meshAgent = GetComponent();
25 SphereRadius = GetComponentInChildren().gameObject;
26 TriggerDest = SphereRadius.GetComponentInChildren();
27 triggerTransform = TriggerDest.GetComponent();
28 animator = GetComponent();
29 WalkRadius = SphereRadius.GetComponent();
30 SphereRadius.transform.parent = null;
31 }
32
33 // checks if the mother has a destination already or if it should find one
34 void Update()
35 {
36 if (hasDestination == false)
37 {
38 NewDestination();
39 } else {
40 float velocity = Vector3.Distance(lastpos, transform.position) / Time.deltaTime;
41 lastpos = transform.position;
42 animator.SetFloat("Speed", velocity);
43 }
44 }
45
46 // sets the destination so it could get a new destination again.
47 public void UpdateDestination()
48 {
49 meshAgent.Stop();
50 hasDestination = false;
51 }
52
53 // finds a postition inside the sphere and sets the world postition of that selected postiton.
54 void NewDestination()
55 {
56 for (int i = 0; i < 30; i++)
57 {
58 Vector3 randomPoint = SphereRadius.transform.position + Random.insideUnitSphere * WalkRadius.radius;
59 NavMeshHit hit;
60 if (NavMesh.SamplePosition(randomPoint, out hit, 1.0f, NavMesh.AllAreas))
61 {
62 Destination = hit.position;
63 hasDestination = true;
64 break;
65 }
66 }
67
68 //Sets the destination that previous was found insdie the sphere and moves to that
69 if (hasDestination)
70 {
71 triggerTransform.position = Destination;
72 meshAgent.SetDestination(Destination);
73 meshAgent.Resume();
74 }
75 }
76}
They way i setup the next position was instead of checking the distance between mother to destination on every frame i did a trigger that i move around and when the mother enters the trigger a new destination will be set

Click Code to Expand

1using UnityEngine;
2using System.Collections;
3
4public class DestTrigger : MonoBehaviour {
5
6 [HideInInspector]
7 public Mothership mothership;
8
9 // when the mother enters the trigger find a new destination
10 void OnTriggerEnter(Collider col){
11 if (col.tag == "MotherTurtle")
12 {
13 mothership.UpdateDestination();
14 }
15 }
16
17 // Debug
18 void OnDrawGizmos()
19 {
20 Gizmos.color = Color.blue;
21 Gizmos.DrawSphere(gameObject.transform.position, gameObject.GetComponent<SphereCollider()>().radius);
22 }
23}
The mother turtle also keeps track on how many baby turtles is lost and adds them to a list for tracking

Click Code to Expand

1using UnityEngine;
2using System.Collections;
3using System.Collections.Generic;
4
5public class Mothership : MonoBehaviour
6{
7
8 [HideInInspector]
9 public int totalLostTurtles;
10
11 List lostTurtles = new List();
12
13 // Looks for all object with the script turtles and then check if they are lost. If the turtle is lost then add them to list
14 void Awake()
15 {
16 foreach (Turtle turtle in FindObjectsOfType())
17 {
18 if (turtle.isLost)
19 lostTurtles.Add(turtle);
20 }
21 totalLostTurtles = lostTurtles.Count;
22 }
23
24 public void returnTurtle(Turtle returnedTurtle, TurtleType turtleColour)
25 {
26 lostTurtles.Remove(returnedTurtle);
27
28 }
29}


Baby Turtle

When the player gets in range with a baby turtle and the turtle haven't been picked up yet. The baby turtle will start jumping and spawn hearths effect to notify the player that the turtle has been found and can be picked up.

Click Code to Expand

1using UnityEngine;
2using System.Collections;
3
4public class BabyTurtle : MonoBehaviour {
5
6 // Public
7 [Header("Particles")]
8 public ParticleSystem pHearts;
9
10 // Hidden
11 [HideInInspector]
12 public NavMeshAgent meshAgent;
13
14 // Private
15
16 // References
17 Mothership motherShip;
18 Turtle turtleScript;
19 Animator animator;
20 HUD UI;
21
22 // Variables
23 int FollowID;
24 bool isInTrigger = false;
25 bool HasRandomIdle = false;
26 bool FollowMother = false;
27 bool HasMotherTurtleStop = false;
28 bool FirstTimeFound = false;
29 bool IsPlayingSound = false;
30
31
32 // On start of the game gets the referances for each variable and removes the UI from the screen.
33 void Start () {
34 meshAgent = GetComponent();
35 meshAgent.enabled = false;
36 animator = GetComponent();
37 }
38
39
40
41 //Checks if the player is close to the babytrutle and dippending if the turlte has been found or not will give diffrent reaction to the player.
42 void OnTriggerEnter(Collider playerCheck)
43 {
44
45 if (playerCheck.gameObject.GetComponent() != null)
46 {
47 isInTrigger = true;
48 pHearts.Play();
49 if (FirstTimeFound)
50 {
51 meshAgent.Stop();
52 animator.SetBool("beenFound", false);
53 animator.SetBool("Retracted", true);
54 } else {
55 animator.SetBool("beenFound", true);
56 }
57 }
58 }
59
60
61 // When the goes away from the babyturtle it then will resume to walk after the player or back to the mother if it has been found
62 void OnTriggerExit(Collider playerCheck)
63 {
64 if (playerCheck.gameObject.GetComponent() != null)
65 {
66 isInTrigger = false;
67 pHearts.Stop();
68 if (motherShip.isMotherInShell == false)
69 if (turtleScript.hasGoneOver == false)
70 if (FirstTimeFound)
71 {
72 meshAgent.Resume();
73 animator.SetBool("Retracted", false);
74 } else {
75 animator.SetBool("beenFound", false);
76 }
77 }
78 }
79}
When a baby turtle is pickup then they will be move to the mother turtle and start following her. The Player will also get a notification that they picked up a collectable.

Click Code to Expand

1using UnityEngine;
2using System.Collections;
3
4public class BabyTurtle : MonoBehaviour {
5
6 // Public
7
8 [Header("Particles")]
9 public ParticleSystem pHearts;
10 public ParticleSystem pCollect;
11
12 // Hidden
13 [HideInInspector]
14 public NavMeshAgent meshAgent;
15 [HideInInspector]
16 public bool hasBeenPickup = false;
17
18 // Private
19
20 // References
21 Mothership motherShip;
22
23 Transform Follow;
24 Interact intract;
25 Turtle turtleScript;
26 Vector3 lastpos = Vector3.zero;
27 Animator animator;
28 HUD UI;
29
30 // Variables
31 int FollowID;
32 bool isInTrigger = false;
33 bool HasRandomIdle = false;
34 bool FollowMother = false;
35 bool HasMotherTurtleStop = false;
36 bool FirstTimeFound = false;
37 bool IsPlayingSound = false;
38
39
40 // On start of the game gets the referances for each variable and removes the UI from the screen.
41 void Start () {
42 UI = GameObject.FindObjectOfType();
43 turtleScript = GetComponent();
44 motherShip = GameObject.FindGameObjectWithTag("MotherTurtle").GetComponentInParent();
45 meshAgent = GetComponent();
46 meshAgent.enabled = false;
47 animator = GetComponent();
48 intract = GetComponentInChildren();
49 }
50
51
52
53 void Update()
54 {
55
56 // Checks if the turtle has not been pickedup
57 if (hasBeenPickup != true)
58 {
59 // Checks if the player inside the trigger. If inside then player can interact with turtle
60 if (isInTrigger == true)
61 {
62 if (Input.GetButtonDown("Interact"))
63 {
64 if (intract != null)
65 {
66 hasBeenPickup = true;
67 pHearts.Stop();
68 animator.SetBool("beenPickedUp", true);
69 playCollectParticle();
70 intract.DestroyInteract();
71 Invoke("FoundTurtle", 1.5f);
72 UI.showTurtleIcon = true;
73 UI.TurtleUICounter();
74 motherShip.foundTurtles.Add(gameObject);
75 motherShip.currentTurtles = motherShip.foundTurtles.Count;
76 }
77 }
78 }
79 }
80 }
81
82
83
84 // Picked up the baby trutle will teleport the babytrutle to the mother and give the player some feedback that turtle just got pickup.
85 // Also checking if this was the first turtle that was found or not and sets an index for the next turtle to use.
86 void FoundTurtle()
87 {
88 transform.position = new Vector3(motherShip.tempLocation.x, motherShip.tempLocation.y, motherShip.tempLocation.z);
89 FirstTimeFound = true;
90 animator.SetBool("beenFound", false);
91 pCollect.Play();
92
93 if (motherShip.foundTurtles.Count == 1)
94 {
95 FollowMother = true;
96 } else {
97 FollowID = motherShip.foundTurtles.Count - 2 ;
98 }
99 meshAgent.enabled = true;
100
101 }
102
103
104 //Checks if the player is close to the babytrutle and dippending if the turlte has been found or not will give diffrent reaction to the player.
105 void OnTriggerEnter(Collider playerCheck)
106 {
107
108 if (playerCheck.gameObject.GetComponent() != null)
109 {
110 isInTrigger = true;
111 pHearts.Play();
112 if (FirstTimeFound)
113 {
114 meshAgent.Stop();
115 animator.SetBool("beenFound", false);
116 animator.SetBool("Retracted", true);
117 } else {
118 animator.SetBool("beenFound", true);
119 }
120 }
121 }
122
123
124 // When the goes away from the babyturtle it then will resume to walk after the player or back to the mother if it has been found
125 void OnTriggerExit(Collider playerCheck)
126 {
127 if (playerCheck.gameObject.GetComponent() != null)
128 {
129 isInTrigger = false;
130 pHearts.Stop();
131 if (motherShip.isMotherInShell == false)
132 if (turtleScript.hasGoneOver == false)
133 if (FirstTimeFound)
134 {
135 meshAgent.Resume();
136 animator.SetBool("Retracted", false);
137 } else {
138 animator.SetBool("beenFound", false);
139 }
140 }
141 }
142
143 // Plays a partical when the turtle has been colelcted
144 void playCollectParticle()
145 {
146 if(!hasBeenPickup)
147 if(!pCollect.isPlaying)
148 pCollect.Play();
149 }
150}
If another baby turtle is picked up then that baby turtle will find the previous picked up turtle and start following that baby turtle.

Click Code to Expand

1using UnityEngine;
2using System.Collections;
3
4public class BabyTurtle : MonoBehaviour {
5
6 // Public
7
8 [Header("Particles")]
9 public ParticleSystem pCollect;
10
11 // Hidden
12 [HideInInspector]
13 public NavMeshAgent meshAgent;
14
15 // Private
16
17 // References
18 Mothership motherShip;
19 Rigidbody rigd;
20 Interact intract;
21 Turtle turtleScript;
22 Animator animator;
23
24 // Variables
25 int FollowID;
26 bool FollowMother = false;
27 bool FirstTimeFound = false;
28
29 // On start of the game gets the referances for each variable and removes the UI from the screen.
30 void Start () {
31 turtleScript = GetComponent();
32 motherShip = GameObject.FindGameObjectWithTag("MotherTurtle").GetComponentInParent();
33 meshAgent = GetComponent();
34 meshAgent.enabled = false;
35 animator = GetComponent();
36 rigd = GetComponent();
37 intract = GetComponentInChildren();
38 }
39
40
41 void FoundTurtle()
42 {
43 transform.position = new Vector3(motherShip.tempLocation.x, motherShip.tempLocation.y, motherShip.tempLocation.z);
44 FirstTimeFound = true;
45 animator.SetBool("beenFound", false);
46 pCollect.Play();
47
48 if (motherShip.foundTurtles.Count == 1)
49 {
50 FollowMother = true;
51 } else
52 {
53 FollowID = motherShip.foundTurtles.Count - 2 ;
54 }
55 meshAgent.enabled = true;
56
57 }
58}
If the mother turtle would go into a shell the then all the baby turtles that's been picked up will jump into their shells as well

Click Code to Expand

1using UnityEngine;
2using System.Collections;
3
4public class BabyTurtle : MonoBehaviour {
5
6 // Hidden
7 [HideInInspector]
8 public NavMeshAgent meshAgent;
9 [HideInInspector]
10 public bool hasBeenPickup = false;
11
12 // Private
13
14 // References
15 Mothership motherShip;
16 Transform Follow;
17 Turtle turtleScript;
18 Vector3 lastpos = Vector3.zero;
19 Animator animator;
20
21 // Variables
22 int FollowID;
23 bool isInTrigger = false;
24 bool HasRandomIdle = false;
25 bool FollowMother = false;
26
27
28 // On start of the game gets the referances for each variable and removes the UI from the screen.
29 void Start () {
30 turtleScript = GetComponent();
31 motherShip = GameObject.FindGameObjectWithTag("MotherTurtle").GetComponentInParent();
32 meshAgent = GetComponent();
33 meshAgent.enabled = false;
34 animator = GetComponent();
35 }
36
37 void Update () {
38
39 // >Follow Types<(there is currently three follow types ( 1.Follow mother trutle, 2. follow the player, 3.Follow babytrutle infront of current ))
40 //
41 // Check if the current babyturtle should follow the mother or the baby turtle in front
42 if (FollowMother == true)
43 {
44 // Checks if the babyturtle should follow the mother or the player(If the player is in the turtle area then babytrutles will start to follow the player)
45 if(motherShip.AISphere.FollowPlayer == true)
46 {
47 Follow = GameObject.FindGameObjectWithTag("Player").transform;
48 } else {
49 Follow = motherShip.GetComponent();
50 }
51 // checks for the babytrutle that was pickedup befor the current one and follows that one(makes the turtles walk in a snake/line form after the mother)
52 } else {
53 Follow = motherShip.foundTurtles[FollowID].GetComponent();
54 }
55
56
57 // makes the movement from the previous set follow type.
58 if (meshAgent.enabled == true)
59 {
60 meshAgent.SetDestination(Follow.position);
61 }
62
63 // Makes a velocity to later check if the turtle has a movement
64 float velocity = Vector3.Distance(lastpos, transform.position) / Time.deltaTime;
65 lastpos = transform.position;
66
67 // checks if the mothertrutle is in shell then all small turtles will go into shell aswell
68 if(hasBeenPickup == true && motherShip.isMotherInShell == true)
69 {
70 animator.SetBool("Retracted", true);
71 meshAgent.Stop();
72 }
73
74 // This make the baby turtle go out from its shell and make it walk or idle again
75 if (hasBeenPickup == true && isInTrigger == false && turtleScript.hasGoneOver == false && motherShip.isMotherInShell == false)
76 if (velocity >= 0.09f)
77 {
78 animator.SetBool("Retracted", false);
79 animator.SetFloat("Speed", velocity);
80 meshAgent.Resume();
81 HasRandomIdle = false;
82 }
83 }
84}