- Home /
how to confine the displacement of a bot to a certain space?
Hi, how do you confine the displacement of a bot to a certain space? I've seen examples of project Mecanim Example Scenes, but not really helped me. See the picture below. I want my bot only walks in the green areas. How do I do that? Through mathematical formulas? I tried by creating gameObjects these areas but do not know how to access all of its points :S
System.Collections.Generic.List<Vector3> listPoints = new System.Collections.Generic.List<Vector3>();
foreach (Vector3 p in area.transform)
listPoints .Add(p);
int rand = UnityEngine.Random.Range(1, listPoints .Count);
posDestiny.x = listPoints [rand].x;
posDestiny.y = 0;
posDestiny.z = listPoints [rand].z;
P.S.: Sorry i could not load the image, I had to do otherwise: [1]: /storage/temp/7721-areas.pdf
I'm unclear about the problem. What is moving the bot? Script? Animation? What does listPoints represent? Is posDestiny the next point the bot is to go or something else? It is pretty easy to test whether a position is in the green or red areas if that is all you need to know.
You can easily calculate if a point is in the green or the red, and therefore you can make sure that any end points that he would travel to will be in the green. But the issue becomes more complex if you have to make sure NPC does not cross the red. You are looking at obstacle-avoidance or pathfinding algorithms. You description of listPoints does not make sense to me in the Unity world. You might be able to do something with the mesh of the collider to figure out a set of possible points, but given your description, a math model might be better.
A box collider and a capsule collider appropriately placed can overlay the red area. When your NPC will get a OnCollisionEnter() when he attempts to enter the space, or you can check ahead of time by doing a Physics.Raycast().
No personal experiences, but I believe with a CharacterController you use OnControllerColliderHit(). Raycasting will work either way.
Answer by ThePunisher · Feb 11, 2013 at 09:24 PM
If you are using the pro version why don't you save yourself the headache of writing a custom solution for that and use the NavMesh feature? It will be so much simpler to define areas your bots can and cant' access.
Watch the video I linked you and if that's the behavior you are looking for (towards the end), then I would recommend using NavMesh.
http://docs.unity3d.com/Documentation/Manual/NavmeshandPathfinding.html http://www.youtube.com/watch?v=TBYviGlF1hI
Your answer
Follow this Question
Related Questions
How to create a movement system for a bot? 0 Answers
Grid Based Movement (Pokemon-like) 1 Answer
Understand how locomotation system works 1 Answer
Locomotion System Character Animation Question 1 Answer
Player Climbing a Ladder? 1 Answer