- Home /
FPS Tutorial Waypoints question
I'm following the FPS tutorial (from unity) to create a Waypoints system.
I've created the waypoint system and it works fine. My problem is that I need to reduce the distance so that each waypoint only connects to the closest waypoint and not to all waypoints around.
I found out that I can control which waypoints are connected with this:
public var kLineOfSightCapsuleRadius = 2.0;
function RecalculateConnectedWaypoints () { connected = Array();
for (var other : AutoWayPoint in waypoints) {
// Don't connect to ourselves
if (other == this)
continue;
// Do we have a clear line of sight?
if (!Physics.CheckCapsule(transform.position, other.transform.position, kLineOfSightCapsuleRadius)) {
connected.Add(other);
}
}
}
But I don't understand how the CheckCapsule works.
Thanks
I've re-tagged your question, as it wasn't actually AI related.
Answer by Ricardo · Jun 28, 2010 at 12:04 PM
You should check the documentation as it spells out what it does rather well. Or is there any part of the description that is unclear?
Update: Your confusion is not only on what CheckCapsule does, but how it's being used. It's used solely to check that there are no obstacles between transform.position and other other.transform.position in a tube of radius kLineOfSightCapsuleRadius. Reducing that value would only reduce the width of the tube that's checked for possible collisions. It does not by itself limit the connections to the shorter waypoint.
If you wish to do that, you should update the code yourself to:
- Check the distance between your waypoint and the one being evaluated.
- If smaller than the last smaller one found, save it.
- If not, move on to the next.
Once you're done with all waypoints, simply connect to the one found to have the shortest distance.
Ricardo do you speak portuguese? it would be easier to communicate
I don't understand what this variable define: kLineOfSightCapsuleRadius
I'm afraid I do not, only Spanish. If you check the documentation, you'll see that it defines the radius for the capsule.
ok..Yeah I understand that but by defining the radius of the capsule only the waypoints that collide with the capsule should be connected right? I have the waypoints 2 units apart..but even with a radius of 1 all waypoints are connected..even the ones that are realy far away
Answer by tomazsaraiva · Jun 28, 2010 at 12:33 PM
I added this line of code and it seems to be working now:
if (!Physics.CheckCapsule(transform.position, other.transform.position, kLineOfSightCapsuleRadius)) {
var distance = Vector3.Distance(transform.position, other.transform.position);
if(distance < 2.1)
{
connected.Add(other);
}
}
Thanks Ricardo
No problem. Bear in $$anonymous$$d that will connect all waypoints within that distance, and not just the closest one (which you mentioned on your question you were going for).
Your answer
Follow this Question
Related Questions
Physics objects sliding along surfaces 1 Answer
Camera gets flung off of the map when the player collides with certain objects. 0 Answers
Punching a crate 0 Answers
Only take into account colliders' bounds on single gameobject in hierarchy 1 Answer
Is it possible to allow a raycast to pass through a collider to hit things behind it? 6 Answers