• 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 tomeromero · Nov 15, 2010 at 10:20 PM · objectrotateenemy

Rotation of my enemy How??

Hi....

I have an enemy that goes from PointA to PointB and then from PointB to PointA....

Here is the script..


var pointB : Vector3;

function Start () { var pointA = transform.position; while (true) { yield MoveObject(transform, pointA, pointB, 3.0); yield MoveObject(transform, pointB, pointA, 3.0); } }

function MoveObject (thisTransform : Transform, startPos : Vector3, endPos : Vector3, time : float) { var i = 0.0; var rate = 1.0/time; while (i < 1.0) { i += Time.deltaTime * rate; thisTransform.position = Vector3.Lerp(startPos, endPos, i); yield; } }


I am new to unity and i need a little help... I want when my enemy goes to PointB to rotate 180 and go back to pointA...but i dont know how to do it...Thank you.

Comment
Add comment
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

2 Replies

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

Answer by JesusChristChangedMe · Nov 15, 2010 at 10:24 PM

here is what you need, just adding transform.rotate to the script and rotating it across the y axis to turn it around.you had almost exactly right.

but here it is

var pointB : Vector3;
function Start () {    
var pointA = transform.position;    
while (true) {        
yield MoveObject(transform, pointA, pointB, 3.0);
transform.Rotate(0,180,0);
yield MoveObject(transform, pointB, pointA, 3.0);
transform.Rotate(0,180,0);}}
function MoveObject (thisTransform : Transform, startPos : Vector3, endPos : Vector3, time : float) {    
var i = 0.0;    
var rate = 1.0/time;    
while (i < 1.0) {        
i += Time.deltaTime * rate;        
thisTransform.position = Vector3.Lerp(startPos, endPos, i);        
yield;     }}

hope this is what you need!

Comment
Add comment · 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
0

Answer by Antonios · Nov 16, 2010 at 12:59 PM

When adding the

Transform

Make sure that the (x, y, z) is correctly set up. Other wise, try using

Transform(x, Quaternion, z)

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 JesusChristChangedMe · Nov 16, 2010 at 08:37 PM 0
Share

Quaternion is only used to define new rotaions to something that already defines a rotaion. Thus you almost never access or change individual Quaternion's (x,y,z,w); most often you would just take existing rotations (e.g. from the Transform) and use them to make new rotations. but Transform(x, Quaternion, z) wont do any good because Quaternion isnt used that way. it would be something like transform.Rotaion(x,y,z); just to clarify. :)

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

Target distance would only update closer 1 Answer

Enemy rotates when hits wall 0 Answers

Rotate Camera around Object 2 Answers

LookAt once 0 Answers

How can I clamp the object up and down rotation from 0 to -90? 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