Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
  • Help Room /
avatar image
0
Question by amitkuliyal · Feb 11, 2017 at 08:30 AM · transformpivotvector3.position

difference between transform.forward and vector3.forward

Hello, I'm learning unity C# and i'm confused between transform.forward and vector3.forward, please teach the difference between these two, here is the code i'm trying and they both giving different results(in this case i wanted vector3.forward)

transform.position = Pivot.position + transform.rotation Vector3.forward -Distance; transform.position = Pivot.position + transform.rotation transform.forward -Distance;

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
11
Best Answer

Answer by Hellium · Feb 11, 2017 at 08:32 AM

Vector3.forward is the unit vector defined by (0, 0, 1)

transform.forward is the forward direction of the object in the world space. It's the direction your object is "looking at", and depends on the various rotation you made on the object.

Supposing you instantiate a simple cube at the root of the scene, its forward vector will be (0, 0, 1). Now, if you rotate the object 90° clockwise on the Y axis, its new forward vector will be (1, 0, 0)

But in your code, you have a specific case :

transform.rotation * Vector3.forward makes the product of a rotation quaternion with the Vector.forward. This operation will result in a direction vector equals to transform.forward

Thus, I don't think transform.rotation * transform.forward is what you really want to do.

Comment
Add comment · Show 3 · 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 amitkuliyal · Feb 11, 2017 at 08:43 AM 1
Share

Thanks for the great explanation.
So basically vector3.forward is the worlds forward direction(universal)

avatar image alpayoguz97 · Apr 21, 2021 at 07:24 PM 0
Share

I still can't understand behind logic of transform.forward. Yes we use this to face character where it moves but I want to understand logic of this. For example how unity know where is the face of my character correctly ?

avatar image Hellium alpayoguz97 · Apr 21, 2021 at 09:19 PM 1
Share

Every object in the game has its own local rotation, i.e the delta rotation in relation to its parent. The global/world rotation of the object is the composition of all those rotations.


 Root → Local Rotation = Global Rotation = (0, 0, 0)
     - Child → Local Rotation = (0, 90, 0) | Global Rotation = (0, 90, 0) ○ (0, 0, 0) = (0, 90, 0)
          - Grandchild → Local Rotation = (90, 0, 0) | Global Rotation = (90, 0, 0) ○ (0, 90, 0) ○ (0, 0, 0) = (90, 90, 0)


The forward vector is the +Z axis obtained after calculating this global rotation.


Note that I've used the ○ symbol here to represent the composition for the sake of the example. Behind the hood its the product of quaternions, not of sum of euler angles. In the example I gave, it turns out to be the sum of the euler angles, but it's rarely the case

avatar image
0

Answer by wrathofjuju · Nov 23, 2020 at 09:30 AM

This post is a couple of years old so not sure if anyone will see this, but I have a follow-up question (forgive me if this should go in a separate post):

I have a script attached to an object to make it rotate around its local Z axis like so: transform.Rotate(Vector3.forward, rotationAmount);

The funny thing is this is actually getting me the desired result, just not sure why:

The object this script is attached to, is the child of a parent object that is also being rotated.

Now, when I rotate the parent object, the child object's rotate script (using Vector3.forward) still seems to rotate the child object around its own LOCAL forward axis (which is actually the desired effect), whereas using transform.forward produces a strange result.

My question, I guess: what's causing this to be the case? Is this something to do with transformation order, or the child object inheriting the parent object's transform info?

I'm actually getting my desired result so I guess it's fine, just kinda baffled as to WHY :)

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 Hellium · Nov 23, 2020 at 09:52 AM 0
Share

Yes, this question should have deserved its own post.

The behaviour you are seeing is normal. It's how the Rotate method works:

https://docs.unity3d.com/ScriptReference/Transform.Rotate.html

Use Transform.Rotate to rotate GameObjects in a variety of ways. [...] You can specify a rotation in world axes or local axes.

By default, it's the local axes which are used for the rotation. transform.Rotate(Vector3.forward, rotationAmount); will rotate rotationAmount around the vector Vector3.forward of the local space of the object (`Space.Self`).

transform.Rotate(Vector3.forward, rotationAmount, Space.World); will rotate the object around the world Vector3.forward axis

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

73 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I rotate a game object around a custom pivot? 1 Answer

Align the bottom of a sprite to the bottom of a collider 0 Answers

How to make a cylinder that dynamically connects two objects? 0 Answers

transform.position not applying to my camera. 1 Answer

UnityException: Transform child out of bounds (C# Unity) 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