# Unity 3D - create autonomous moving robot in house + first person camera movement

I have very, very little knowledge about programming or Unity. I have done some basic tutorials, but I want to try something harder. The thing is, I don't know where to start. If you find the time to help out a newb like myself, I thank you greatly :)

Scenario

I bought this asset: https://www.assetstore.unity3d.com/en/#!/content/48976 (it's a 3D model of a house). I want a robot, a UGV (unmanned ground vehicle) to move through the house, randomly. I want a first person view in the game, where the person playing the game can move with his mouse + WASD. In the house, I will "hide" some objects that the robot should be able to recognize. For example, I will hide a guitar in the house. When the guitar is visible to the robot, I want it to report to me via some sort of message screen. I want it to be able to "communicate" with the person walking through the house.

Now, I have absolutely no idea what to do.. I have the house.. I can get my hands on a UGV + guitar model.. I know how to attach some scripts to the first person so it can move.

My questions:

how can I randomly move the robot asset through the house?

How can it detect certain objects? Is it done through tags?

How can the robot communicate with the person playing, walking through the game?

If someone has some leads for me, I would love to hear from you!

• Your question touches the hardest's topics in game development, IA, pathfinding and recognition. this said, you should read more about how Unity works, how to import assets, instantiate objects, move them around and append scripts, also, you will need to learn real JS or C#, there's really good material all over the internet. After you feel confident with the engine you can start building your project, i recommend you to start with NPC random movement, then you can move to obstacle avoiding, etc. After that you will have a background enough to achieve your goal. Don't run before walking – PRDeving May 26 '16 at 20:13

I do have some answers for you:

how can I randomly move the robot asset through the house?
The robot would have to set a new random target, once it reaches it's previous. This could be done by selecting a random one out of several predefined target points.

Alternatively, you could attach a standart character controller to the robot and controll it using your own script. Use a Vector3 variable as the input for the character movement and change it to a random value every 2 - 4 seconds. In order to avoid the robot running into walls, you can also have it check, if it's position changed and force it to generate a new Vector3, if it got stuck.

How can it detect certain objects? Is it done through tags?
You can get the tag or name of a GameObject with myGameObject.tag or myGameObject.name. "Finding" objects can be done by using ray casting.

How can the robot communicate with the person playing, walking through the game?
There are multiple solutions to communicating between two scripts in Unity. Since you are probably only using two (Player and UGV), I think you can use the following example:

public class Player : MonoBehaviour{
public UGV ugv; //assign this variable in the inspector, or using another method

public void CallMethodAInUGV(){
if(ugv != null){
ugv.MethodA();
}
}

public void MethodB(){
//do something (Player)
}
}


...same for the Robot:

    public class UGV: MonoBehaviour{
public Player player; //assign this variable in the inspector, or using another method

public void CallMethodBInPlayer(){
if(player != null){
player.MethodB();
}
}

public void MethodA(){
//do something (Robot)
}
}


As said previously, this is just one of multiple solutions.

• Thanks a lot for your supportive reply. I will focus on your points this weekend, and if that's alright with you, I will ask some questions here if I don't seem to find a feasible solution. Thanks once more and have a great weekend! – juuljuup May 27 '16 at 11:01
• Great! Maybe I'll be able to edit my question over the weekend to include more code examples, if I have the time to do so. – 000000000000000000000 May 27 '16 at 11:33
• I got some progress. With your script, I can get the UGV to move to 1 particular gun (defined by the Gameobject I can select in the inspector). But I want this: have the UGV move from 1 gun to the next. I have no idea how to code this. I have been reading and trying for several hours, but maybe you know something? I was thinking like this: public class MoveTo : MonoBehaviour { goal = GameObject.FindGameObjectsWithTag("Pietje").transform; void Start () { NavMeshAgent agent = GetComponent<NavMeshAgent>(); agent.destination = goal.position; } – juuljuup May 29 '16 at 10:27
• Please post a new question and the link to it as a comment here. I'll see, if I can help you. – 000000000000000000000 May 29 '16 at 12:47
• see the following question: gamedev.stackexchange.com/questions/122120/… – juuljuup May 29 '16 at 18:04