• 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
0
Question by Paparakas · Mar 04, 2013 at 07:47 PM · spacelocalworld

Can someone help me understand world/local space?

Everytime I think I understand it something comes up and I get confused again.

So say I have this code:

 var coconutObject : Rigidbody;
 var throwForce : float;
 
 function Update () {
 
 if(Input.GetButtonUp("Fire1")){
 
   var newCoconut : Rigidbody = instantiate(coconutObject,transform.position,transform.rotation); 
 
 newCoconut.rigidbody.velocity = 
 transform.TransformDirection(Vector3(0,0, throwForce));

The documentation says it transforms local into world. Alright. But say I'm adding this to an fps controller so and I want it to shoot coconuts in my forward direction. Shouldn't making it into world space, like the TransformDirection does, always make it always go to the WORLD'S z and not the local z? So basically no matter where I turn my character, it should always shoot the coconuts in in the same direction, because they're going forward in the world's z. But it does the opposite! It shoots the coconuts depending on where I turn, but wouldn't that be local z? Because unlike the world z, my local z will always change depending on where i'm turning. Instead, when I DON'T use the TransformDirection, it ALWAYS goes in the same direction. This has been annoying me for a while now and I really want to get this down so I can better understand what i'm doing with unity.

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

1 Reply

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

Answer by kramcomposer · Mar 04, 2013 at 08:36 PM

rigidbody.velocity is stored as a World Direction So you Just want to feed it Vector3(0,0,1);

When you use transform.TransformDirection its Asking for a LocalSpace Direction (which you are feeding it a Local Direction of Vector3(0,0,1); and Its converting it into a WorldSpace Direction, basicly, the way your character is Facing.

Another way to put this is~

the Vector3 Struct doesn't know weather its a World Direction, World Position, Local Position, or Relative Direction. it just holds and X,Y, & Z

You have to keep track of what you Vector3 vars are holding...

I hope that makes some sence

And ultimately, just do this:

 newCoconut.rigidbody.velocity = new Vector3(0,0, throwForce));
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 Paparakas · Mar 04, 2013 at 09:35 PM 0
Share

I already understand it now , and honestly, the thing you told me to ultimately do is really bad. Since you're inputting a local variable, when it gets changed into a world variable it will always be the same. So if i turned , the velocity would still be at the same place. So everytime a new coconut gets instantiated it will always shoot the coconut at the same direction no matter where im turning. So in this case transform.TransformDirection(Vector3(0,0, throwForce)); would be better since it transforms the local variable into a world variable for you.

avatar image kramcomposer · Mar 04, 2013 at 09:40 PM 0
Share

I guess I didn't understand your question very well, I thought you always wanted the Coconut to move in the world direction of Z forward?

If you want the Coconut to move the direction of the way the character is facing, you can just do this.

 newCoconut.rigidbody.velocity = transform.forward * throwForce;

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

11 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

Related Questions

Defining a local spawn offset 1 Answer

Converting Raycasted Point to Local Space 2 Answers

Is there a local method for Rigidbody.constraints? 0 Answers

Apply a Rotation in World Space based on Quaternions 2 Answers

World and Local Axis out of Alignment 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