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
0
Question by arboshiki · Jan 11, 2013 at 08:45 PM · rigidbodyinstantiatetransformpositiondirection

Use GameObject's global position instead of local position

alt textHello everyone, I am new in unity and I am trying to create a level myself, but I have a problem. As you see on the first picture the position of cylinder is local. alt text On the second picture the position of the cylinder is global, I have function OnTriggerEnter in which am instantiating an arrow on the cylinder position with its rotation and throwing it. I want the arrow to be thrown to y direction in local position. But I do not know how, it is done in global(world position). If anyone knows how to throw an arrow in y direction in local scope. Here is code: var clonedArrow = Instantiate(arrow,bow.transform.position, bow.transform.rotation); clonedArrow.rigidbody.velocity = bow.transform.TransformDirection(Vector3(0,20,0));

arrow is a public variable of type GameObject from prefab(which has rigidbody already). Bow is my cylinder. Thank you beforehand

global.png (478.0 kB)
local.png (352.0 kB)
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
-2

Answer by arboshiki · Jan 14, 2013 at 12:15 PM

Thank you very much, I did what I want.

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 Seth-Bergman · Jan 14, 2013 at 03:41 PM 0
Share

please don't post comments as answers, and please click the CHEC$$anonymous$$ $$anonymous$$AR$$anonymous$$ to accept an answer if it helps you

avatar image
0

Answer by Julien-Lynge · Jan 11, 2013 at 09:17 PM

You need to spend some time investigating the Transform class. Everything you need to access both local and global coordinates is in there, and it's named very obviously.

http://docs.unity3d.com/Documentation/ScriptReference/Transform.html

For your TransformDirection stuff, take a look at things like up, right, and forward.

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 Seth-Bergman · Jan 11, 2013 at 09:45 PM

First off, this

 bow.transform.TransformDirection(Vector3(0,20,0));

(same thing as)

 bow.transform.up * 20;

http://docs.unity3d.com/Documentation/ScriptReference/Transform-up.html

this takes the local direction and converts it to world coordinates... in other words, the direction in question is in fact already based off of the local direction..

(y being the green axis)

so this already IS LOCAL!

(just tested your code to be SURE, it already does exactly what you say you want)

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 Seth-Bergman · Jan 11, 2013 at 10:21 PM 0
Share

also, p.s...

if an answer solves your issue (such as):

http://answers.unity3d.com/questions/368033/a-little-problem-in-partciles.html

please be sure and click the check mark by the answer to accept it!

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

10 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

Related Questions

How to follow multiple clones positions of an instantiate prefab having a velocity ? 1 Answer

Take final position after a force applied to a GameObject 1 Answer

How can I get a GameObject's transform in game and set that to a variable? 1 Answer

Moving object with transform.position ignore other objects even if they collided 1 Answer

How do I get the opposite position of an object that spins around another object... 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