In the scene i have a space station but not terrain.
The space station have many many MeshRenderers.
The problem is that when i click the Bake button i see a message in the inspector: Select a MeshRenderer or a Terrain from the scene.
What i want to do is to make the character to move around the space station randomly. I mean to random places in the spaceship.
I can’t figure out yet some things:
About the baking problem as mentioned above.
What should i do or the character when he get to a door ? In the space station the doors open/close automatic when i move close to them. What will happen when the character will move automatic and will get close to a door or a wall ?
If the character is getting to a place where he can go right,left,straight what the character will do ? In my logic he should make random selection where to go. But i wonder how to do it ?
I have a third person character and added to him a Nav Mesh Agent component and didn’t change anything yet in the inspector. Should i change something on the nav mesh agent for now ?
I also saw in the unity tutorial that i should set a target where the agent the character should go to. But i want the character to walk random aorund the space station. Do i need then to add random targets around the station ?
I didn’t write yet the script. I’m not sure what should i do. I can get the nav mesh agent component in the script and also to set destination as target but i want the character to move around the space station randomly so do i need to add random targets around ?
[code[
using UnityEngine;
using System.Collections;
Hi, I see noone answered you, but I think I can help a bit.
1). stage 1
First, if you are making a game with random pathes, start with simple. I did in this way: first make a 2d game where enemy can move within one line (just set maximim X as coordinate1, and minimum X as coordinate2). Thus, you need to add two variables for enemy: minX and maxY. Then set destination for navmesh agent to walk to that minX/maxX. You’ll need one variable for currentX position. If your enemy reaches minx (if (curerntX == minX)) - then set destination to MaxX.
If you can do that with Vector3.MoveTowards, then only try doing same with navmeshagent.setdestination.
2). stage 2
Once you have working script for 2d walking of enemy, go into 3d space.
for that I used level generator with rooms and corridors. What is important for you in this case is to know the corners of rooms. Each room would have 4 corners, and enemy would walk only within one room. Begin with this simple, then you can add more complicated logic for more rooms.
Add 4 variables first:
public GameObject Corner1;
public GameObject Corner2;
public GameObject Corner3;
public GameObject Corner4;
stage 3. I advice don’t use level generator. If it’s like that, then you can make an area, which consists of square/rectangle areas for enemy to move within. Then logic is the same: move within 4 corners withing each area.
Just add trigger unto a door. If you have it (just add component collider, and set trigger checkbox), you can code it. use function like OnTriggerEnter (Unity - Scripting API: MonoBehaviour.OnTriggerEnter(Collider)) or Unity - Scripting API: Collider.OnTriggerStay(Collider)
when you’ll come to a door, trigger would have to check if entered gameobject is a player, if yes - open a door. (well, it probably should work same for enemies, unless you use a key to open doors)…
don’t try to decide every second/frame (in Update) where to go. Because then movement would be chaotic. Just decide one destination (if your enemy doesn’t move on Y coordinate, just generate random X and random Z within minX/maxX and MinZ/maxZ) and he would go. Maybe it is not best approach, but something is better than nothing. AI is complicated thing, so be patient…
Just set stoppingdistance to something around 0.5(f), because otherwise player would try to go unto some obstacles/walls/enemies etc, so stopping distance is a good variable…
make array of empty GameObjects which are kind of corners of “rooms”/areas, and assign them for your enemy AI script to walk to. That’s it…
yes, I think you can bake cubes, and walk on them. not sure. but why you don’t use terrains? if that’s space station, there you can use scaled down terrains which would work as meshes for baking.