- Home /
How to make waypoints
Hi In the game were making we need to know how to make way points in unity. The only problem is that were all noobs and don't know how to. Please help.
Answer by Kaha · Jan 20, 2013 at 07:32 PM
Hi,
How can I make a loop in the waypoints Transform ?
Right now the Enemy is doing: 0>1>2>3>4>5 And I'd like him to do: 0>1>2>3>4>5>0 and continue looping.
Any idea ?
If done the loop using this tutorials : http://www.youtube.com/watch?v=-5Ri$$anonymous$$oILHTA
if ( currentWaypoint >= waypoints.length ) {
currentWaypoint = 0;
}
Answer by Tuben · Sep 12, 2012 at 09:54 PM
Hey is it possible too add somthing too this script so the enemy/npc turn(rotate) too the next waypoint? mine is currently only sliding too the next one. thanks!
Answer by oliver-jones · Nov 25, 2010 at 09:08 PM
Hahah, Class!
Okay, well here is what I use, all it does it allows enemies to follow a waypoint one after another
var waypoint : Transform[]; static var speed : float = 5; private var currentWaypoint : int;
function Update ()
{
if(currentWaypoint < waypoint.length)
{
var target : Vector3 = waypoint[currentWaypoint].position;
var moveDirection : Vector3 = target - transform.position;
var velocity = rigidbody.velocity;
if(moveDirection.magnitude < 1)
{
currentWaypoint++;
}
else
{
velocity = moveDirection.normalized*speed;
}
}
rigidbody.velocity = velocity;
}
This goes in your enemy!
This code below, goes into a game empty:
// Draw the waypoint pickable gizmo
function OnDrawGizmos () {
Gizmos.DrawIcon (transform.position, "Waypoint.tif");
}
Now with that, what you do is create a game empty on your scene, then drag that script onto with. Where ever this point is, the enemy will walk to it. You can have more than one waypoint. Just means the enemy will walk to one waypoint, then to the other
BTW -- the Waypoint.tif is just an image that is placed over the top of your waypoint - so you can see it. To get yours working, create a file in your project called 'Gizmos', then place a simple small image in there, then call it Waypoint.tif
The "rigidbody.velocity = velocity;" line needs to go inside the closing brace } above it -- otherwise velocity is not defined. Normally wouldn't comment on something so obvious, but there is an incorrect answer that could misslead folks -- will comment on that also.
Here are some of the errors that popped up: Assets/Path.js(5,27): BCE0044: expecting ), found ';'. Assets/Path.js(5,44): BCE0043: Unexpected token: ). Assets/Path.js(11,35): BCE0044: expecting ), found ';'. Assets/Path.js(11,37): BCE0043: Unexpected token 1. Assets/Path.js(15,5): BCE0044: expecting }, found 'else'. There are many $$anonymous$$ANY more errors that came with this script. I honestly don't know what I did wrong but if you can help me fix these please tell me.
Answer by Loius · Nov 25, 2010 at 09:13 PM
There are tons of different ways.
The solution above may work for you. Personally I prefer using a spline path (Bezier curves faded together, basically; the forum has a few implementations available) which represents the optimal drive line. You then have each car attempt to match their rotation to the path's direction at the closest point to the car.
Answer by Kota · Jul 18, 2011 at 07:40 PM
Console says (unknown identifier: "velocity") Is says this for last line of code on the first script (rigidbidy.velocity = velocity;)
I deleted that last line but when I ran the game the cylinder that had the script attached to it didn't move
Your answer
Follow this Question
Related Questions
Cars in City 0 Answers
Check whether car has passed a point in world space 1 Answer
How To Add AI To Car/Racer? 4 Answers
Car- can someone help me convert this to C#? 1 Answer
Steering an AI vehicle to a waypoint using float of -1 to 1? 1 Answer