- Home /
Waypoint System Does Not Rotate Enemy?
Hello,
My waypoint system does not rotate my enemy according to the direction of the waypoint. Here is my script:
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;
}
Any suggestions why? Thanks. Ollie
I don't understand why the word rotation itself is not part of the script? What code section or specific line do you expect will do this for you?
I tried waypoint[currentWaypoint].rotation as well as position - but I get an error
well that code sets the rotation of the waypoint. You want to change the rotation of the transform that is being manipulated I assume. You could do extract the information of current point and destination point and calculate the angle with trig. using both transforms and their difference in respectively x,y,z
Answer by Mike 3 · Dec 09, 2010 at 10:50 PM
You could add
transform.LookAt(currentWaypoint);
right after you set rigidbody.velocity
Edit (To set it to only rotate around x):
var lookAt = currentWaypoint.position - transform.position; lookAt.x = 0; //if you want to rotate around only y, set lookAt.y to 0 instead
transform.rotation = Quaternion.LookRotation(lookAt);
This works - but how do I set it to only the X axis of the transform?
Answer by AsemaKhan · Dec 10, 2010 at 02:21 PM
Am sorry I dont know the answer to your question but here I need some help , =(
I have a question to you "Oliver Jones" . Can you please tell me how to add enemy Ai , what tutorials you are following please give me some guidelines .
Well, this is off topic - but my AI is, well - VERY basic. All it allows is for an enemy to talk to one point, and then to another - and then another. If you click on my profile, you will find my email - send me a message and I'll help you out.