• 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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Rotating a direction Vector3 by Quaternion 2 Answers

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

Dynamically change Vector3.up/right?,How to make a cylinder chase mechanic? 2 Answers

Checking vector3 gameObject is about to move to (pathfinding collision detection) 1 Answer

Quaternion amount/value of rotation? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges