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 redteardrop · Oct 06, 2012 at 04:10 PM · instantiatevector3transform.translateworld spacelocal space

Create variable based on local axis

I am trying to instantiate 2 objects when one object gets destroyed. The problem is that if the rotation isn't straight up it gets instantiated at the wrong position.

var rot:Quaternion = transform.rotation;
var targetBlock : GameObject;
tempPos2 = Vector3(transform.position.x,transform.position.y,transform.position.z+2);
tempPos3 = Vector3(transform.position.x,transform.position.y+2,transform.position.z);
var oneBlox : GameObject;
oneBlox = Instantiate (targetBlock, tempPos2, rot); oneBlox = Instantiate (targetBlock, tempPos3, rot);
Problem is that the tempPos variables seem to be in world space. I need them to be local so it'll move the instantiated blox to the correct spot relative to the original object and it's rotation. I tried transform.Translate using Self space, but can't get it to work on the instantiated objects since it'll need to spawn in the correct world space then adjust to the correct relative local space from the now destroyed original object. Here's the question I suppose: How can I get a Vector3 variable to work with local and world space to get the instantiated object in the correct world position?

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 rhys_vdw · Oct 06, 2012 at 04:25 PM

Use Transform.TransformPoint(). It will take a point in local co-ordinates, and translate it to world co-ordinates.

 var rot : Quaternion = transform.rotation;
 var targetBlock : GameObject;
 
 tempPos2 = transform.TransformPoint(Vector3.forward * 2);
 tempPos3 = transform.TransformPoint(Vector3.up * 2);
 
 Instantiate (targetBlock, tempPos2, rot);
 Instantiate (targetBlock, tempPos3, rot);

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 redteardrop · Oct 07, 2012 at 04:10 PM 0
Share

Very nice, thanks. I was hoping there was a built in way of doing it without needing sin and cos of the angles doing the whole trig thing.

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

Problem with bullet projectiles direction 2 Answers

Runtime bridge creator 0 Answers

overlapping object doesn't disable 1 Answer

I need help with the location of instatiated objects on the scene and correct interaction with this 2 Answers

How to instantiate an object BEHIND my current position? 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