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
-1
Question by Grimshad · Apr 26, 2013 at 06:21 PM · rotationvector3

Convert local forward into world vector

I have a object that travels from point a to point b. I was using transform.LookAt() and then transform.forward to get the correct direction to move the object in the desired direction.

Now I need to rotate that object, but keep it always moving in the same direction. Obviously when the object rotates it constantly has a new transform.forward which is no longer the desired direction I want it to travel.

So what I was thinking is i could take the transform.forward of the object before it starts rotating, then convert that vector3 into a world vector instead of local. Then the object can move in the correct direction based on world coordinates instead of local coordinates while it's rotating.

Will this work? How would I conver the local vector into a world vector? (i tried TransformDirection and it didn't seem to work). Is there a better way of getting an object to move in a specific direction while it rotates? How?

Comment
Add comment · Show 1
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 Jessy · Apr 26, 2013 at 06:37 PM 0
Share

Transform.TransformDirection(Vector3.forward) is equivalent to Transform.forward.

1 Reply

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

Answer by Jessy · Apr 26, 2013 at 06:36 PM

Transform.forward is in world space. Just store that Vector3 before you rotate the object.

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 Grimshad · Apr 26, 2013 at 07:30 PM 0
Share

I actually tried that before I asked this question. It does the same thing as using current transform.forward. I'll try it again and see what happens.

with that the object still just moves forward based on its rotation and not based on the rotation that it started out at. basically I got something like this:

 var forward :Vector3;
 var rotation :Vector3;
 var speed :float;
 var location :Vector3;
 
 function Start()
 {
  transform.LookAt(location);
  forward = transform.forward;
 }
 
 function Update()
 {
  transform.Rotate(rotation);
  transform.Translate(forward*speed*Time.deltaTime);
 }
 
avatar image Jessy · Apr 26, 2013 at 09:24 PM 0
Share

Your code fails because you're not using the second parameter of Transform.Translate. You need to do a better job of reading the documentation, as far as vector spaces go.

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

13 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Help to figure a logic to achieve a movement. 2 Answers

Unable to fully rotate GameObject on tap 2 Answers

Having Trouble with Vector3.Angle 1 Answer

Get rotation from hit object 1 Answer

Workaround for Quaternion.eulerAngles 360 Degree Limit? 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