Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

rotate vector around local axis 2 Answers

Rotate object based on hit normal + matching camera direction 0 Answers

C# Raycast from Object direction (z-axis) + another Vector3 1 Answer

Get rotation from a vector direction. 1 Answer

3D nested Turret Prefab Rotation 1 Answer


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