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 Linus371 · Apr 09, 2013 at 12:58 PM · transformvector3axis

Problem with Vector3 direction and axises.

Hello! I'm getting an headache now with dealing with these Vectors and Axises. This is going to be hard to explain, but please bear with me.

What I'm trying to do, is to find the Vector3 direction to the right of the object, but ignoring the y-axis, somehow. My first thought was obviously:

transform.right

Though, this doesn't quite work: alt text

As you can see, the y-axis is not ignored, and the Vector doesn't point to the right, but to the right AND down.

Rather, this is what I want: alt text As you can see, it's pointing to the right, ignoring the y-axis. You might think of using:

 Vector3.right

Which works when the object is NOT rotated around the y-axis, but when the object IS rotated around the y-axis it DOESN'T work.

So, anyone who can help me? I've run into this problem so many times, and I cannot find a solution. Help would be highly appreciated!

Thanks in advance!

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Bunny83 · Apr 09, 2013 at 01:41 PM

I guess you simply want:

 var dir = transform.right;
 dir.y = 0;
 dir.Normalize();
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 Bunny83 · Apr 09, 2013 at 01:43 PM 0
Share

$$anonymous$$eep in $$anonymous$$d when you rotate the objects right vector towards the world up vector, the vector will become 0,0,0 since it consists only of an y-part which is stripped away.

avatar image
0

Answer by AVividLight · Apr 09, 2013 at 01:24 PM

Hey Linus371,

I don't think I understand your question very well, so please forgive me if I ask something stupid here.

So, you want to know a direction in 1d space? If that is the case, I would need more information about what you're actually try to do to provide a good answer, but I will suggest thinking a bit more creatively. By that, I mean maybe make the object a child of an emptyGameObject, and get the direction from the parent. Maybe it would be as easy as using the objects X-valuse + 2?

I'm sorry if this isn't a good answer! -Gibson

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 LyanApps · Apr 09, 2013 at 06:50 PM

I'm thinking what you're saying is your object is rotated on the z-axis. You should look up some trigonometry functions or remember SOH CAH TOA. The other name for this is vector projection. http://www.youtube.com/watch?v=7o4b10xroEM

Also don't forget you have the difference between local coordinates and world coordinates.

 //var x = hypotenuse * cos (angle)
 var x = 1 * Mathf.Cos(transform. localEulerAngles.z * Mathf.Deg2Rad);
 //Vector in local direction
 Vector3 localv3 = new Vector3(x,0,0);
 //Transform to World Coordinates
 Vector3 worldv3 = transform.TransformPoint(localv3);
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

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

Find a Position on the Axis of a GameObject 1 Answer

Moving a Platform 1 Answer

Why using = isn´t fast enough for changing Vector3 values from the transform? 2 Answers

How do I make one transform rotation the same as anothers? 2 Answers

Player rotation = Camera Rotation 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