x


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

more ▼

asked Dec 09 '10 at 09:32 PM

oliver-jones gravatar image

oliver-jones
2.5k 206 226 254

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?

Dec 09 '10 at 09:42 PM Proclyon

I don't know how it insert it - or where.

Dec 09 '10 at 09:46 PM oliver-jones

I tried waypoint[currentWaypoint].rotation as well as position - but I get an error

Dec 09 '10 at 09:46 PM oliver-jones

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

Dec 09 '10 at 10:11 PM Proclyon
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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);
more ▼

answered Dec 09 '10 at 10:50 PM

Mike 3 gravatar image

Mike 3
30.5k 10 65 253

This works - but how do I set it to only the X axis of the transform?

Dec 09 '10 at 11:11 PM oliver-jones
(comments are locked)
10|3000 characters needed characters left

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 .

more ▼

answered Dec 10 '10 at 02:21 PM

AsemaKhan gravatar image

AsemaKhan
34 9 9 13

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.

Dec 10 '10 at 03:14 PM oliver-jones
  • by talk - I mean't walk *
Dec 10 '10 at 03:14 PM oliver-jones
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2173
x580
x286
x170

asked: Dec 09 '10 at 09:32 PM

Seen: 1212 times

Last Updated: Dec 09 '10 at 09:32 PM