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
11
Question by 3dDude · Jan 31, 2012 at 01:11 AM · transformparentdirectionlocal

getting object local direction?

Its been a while since I have tried to script and I cannot figure this out..

I am trying to get the local direction of a parent object so I can add local force to a particle with a script. And I thought that

 transform.parent.up

gave you the local direction and it worked in one situation but not in another. It just seemed to use the world direction as the scripting reference says..

So my question is how do I get the local up direction of a object?

Thanks!

Comment
Add comment · Show 10
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 syclamoth · Jan 31, 2012 at 01:21 AM 0
Share

transform.up should give you the local up direction- in what situation does 'transform.parent.up' not give you the correct value?

avatar image syclamoth · Jan 31, 2012 at 01:31 AM 0
Share

What's wrong with that? Why doesn't it give you the correct value? It's possible that it's a problem with your logic.

avatar image 3dDude · Jan 31, 2012 at 01:38 AM 0
Share

Well I don't really know.. It seemed to work in one instance. But in a different one it just seemed to give it world up force.

I am creating explosions on impact and they need to have gravity based on there angle. so I thought that changing there force in a Start function with that code would work..

avatar image syclamoth · Jan 31, 2012 at 01:41 AM 0
Share

Remember that the particle animator has setting for both world, and local, forces. If you set up the local force, you just need to rotate the object, and the particle animator will handle the rest. REDACTED no wait that's wrong.

avatar image 3dDude · Jan 31, 2012 at 02:17 AM 0
Share

I am not using shuriken particles.. I don't see a way to make local force on the old system.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
49

Answer by gabs · Feb 09, 2012 at 08:28 PM

All the possible direction vectors, not sure if you want a local or global:

 using UnityEngine;
 using System.Collections;
 
 public class DrawSampleVecs : MonoBehaviour
 {
     void OnDrawGizmos()
     {
         Color color;
         color = Color.green;
         // local up
         DrawHelperAtCenter(this.transform.up, color, 2f);
         
         color.g -= 0.5f;
         // global up
         DrawHelperAtCenter(Vector3.up, color, 1f);
         
         color = Color.blue;
         // local forward
         DrawHelperAtCenter(this.transform.forward, color, 2f);
         
         color.b -= 0.5f;
         // global forward
         DrawHelperAtCenter(Vector3.forward, color, 1f);
         
         color = Color.red;
         // local right
         DrawHelperAtCenter(this.transform.right, color, 2f);
         
         color.r -= 0.5f;
         // global right
         DrawHelperAtCenter(Vector3.right, color, 1f);
     }
     
     private void DrawHelperAtCenter(
                        Vector3 direction, Color color, float scale)
     {
         Gizmos.color = color;
         Vector3 destination = transform.position + direction * scale;
         Gizmos.DrawLine(transform.position, destination);
     }
     
 }

Also remember that Transform.eulerAngles can be useful.

direction vecs

Comment
Add comment · Show 4 · 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 Josh707 · Dec 29, 2012 at 06:39 AM 1
Share

Great example have a thumbs up

avatar image kaleidosgu · Jun 06, 2017 at 01:52 AM 1
Share

It's very useful. Thanks.

avatar image akashranjansingh95 · Aug 27, 2017 at 02:25 PM 1
Share

Thanks a lot

avatar image Piyush_Pandey · Mar 19, 2018 at 10:29 PM 1
Share

Thank you you life saver. You deserve a full pitcher beer from me!

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

12 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

Related Questions

Problem retrieving transform.position after parent rotation 1 Answer

Parenting GameObjects 1 Answer

Transform position of an object at particular angle/direction 3 Answers

Unity 3D: How to pick up object and attached it to player on TriggerEnter? 1 Answer

Changing child's rotation changes parent's position 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