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 Khm666 · Oct 23, 2010 at 11:11 AM · transformdirectioncarvectorforward

How can I change the "forward" direction of my model?

in the car tutorial how can i change the forward vector for the car ? the complete scene setup the forward is pointing 45' degree to the track street i want the forward for the car to point always to the front of the car

this.transform.LookAt(this.transform.forward);

If i used the above code into the tutorial car it always look at 45' degree it doesnt look straight to the track road.

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

5 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by duck · Oct 23, 2010 at 12:53 PM

Sounds like your car has been modelled in your 3d modelling app with its origin (pivot) pointing in the wrong direction.

This is best fixed in the 3d app itself, although you can work around it by parenting your car model to an empty 3d game object. Then you can treat the empty game object as if it were the car (i.e. place scripts on it), and have the incorrectly aligned car model as a child, rotated to face the correct way.

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 Khm666 · Oct 23, 2010 at 01:43 PM 0
Share

i'm using the car from the tutorial itself the red one, the global forward for the car is 45' ! why is it like this ? the local is pointing toward the street but when i use the code above its not pointing toward the street !

avatar image
1

Answer by KSP_Bro_AE · Oct 31, 2018 at 07:49 AM

After the transform.LookAt, you shut put: transform.Rotate(new Vector3(/*experiment here until it works*/)); No redoing 3D model, no parenting to empty, just a line of code.

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
1

Answer by Cornelis-de-Jager · Mar 06, 2019 at 09:09 PM

How i tend to get around this fairly easily is by putting my model in its own gameObject. I then child that game object to another transform which contains the movement scripts. Meaning I can rotate and change the position of my model any time without effecting the movement direction.

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
1

Answer by highpockets · Mar 06, 2019 at 11:32 PM

LookAt takes a transform or position as an argument, not a direction. The direction vector passed with transform.forward is going to be the normalized direction of wherever the cars z axis is pointing, but the cars z axis will lookat the world origin (0,0,0) + the normalized direction vector which may be 1,0,0 for example. So it will look at 1,0,0 in world space.. The proper use of LookAt in this case would be: LookAt(carsPosition + carTransform.forward) .. That is assuming that the car model’s z axis points toward the front of the car, if it’s not pointing to the front of the car than choose the direction that is (the red right direction vector for example) and use that instead..

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 hal0zer0 · Mar 06, 2019 at 08:49 PM

Neither of these responses was appropriate for my situation (which involved an auto-follow camera following from the wrong side) - I ended up just sticking a cube inside my backward model (optionally disabling the mesh renderer) and making THAT the target for my camera

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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How do you turn object to face a particular vector ? 1 Answer

Object hold and mouse roll 1 Answer

Tranposing two 3D coordinates onto a 2D plane? 1 Answer

Finding the difference between two directions? 0 Answers

Converting Direction Vectors In Children Manually 0 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