• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by oliver-jones · Dec 09, 2010 at 09:32 PM · rotationvector3directionwaypoint

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 &lt; 1)
     {
         currentWaypoint++;
     }
     else
     {
         velocity = moveDirection.normalized*speed;
     }
 }

 rigidbody.velocity = velocity;

}

Any suggestions why? Thanks. Ollie

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Proclyon · Dec 09, 2010 at 09:42 PM 1
Share

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?

avatar image oliver-jones · Dec 09, 2010 at 09:46 PM 0
Share

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

avatar image oliver-jones · Dec 09, 2010 at 09:46 PM 0
Share

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

avatar image Proclyon · Dec 09, 2010 at 10:11 PM 0
Share

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image oliver-jones · Dec 09, 2010 at 11:11 PM 0
Share

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

avatar image
0

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 .

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image oliver-jones · Dec 10, 2010 at 03:14 PM 0
Share

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.

avatar image oliver-jones · Dec 10, 2010 at 03:14 PM 0
Share
  • by talk - I mean't walk *

Your answer

Hint: You can notify a user about this post by typing @username

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

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

How to get offset postition after rotation ? (Spent hours figuring it out) 3 Answers

Get Direction from 2 Vectors - and Apply to Transform 0 Answers

Rotate vector3 relative to another vector3 1 Answer

Vector3.SignedAngle wrong direction when crossing the 0 point 1 Answer

rotate vector around local axis 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges