Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 TheEmeraldRuby · May 15, 2018 at 05:58 PM · instantiateprefabquaterniontransform.position

How to instantiate prefabs with offset transform.position values?

I am making a game where different obstacle prefabs are randomly instantiated into the scene. They all have different sizes and are thus positioned on the Y axis to be placed right on the flat ground, so I just want to know how I would tell Unity to instantiate them with their transform.position offsets kept in mind (kind of like Quaternion.Euler). If anyone knows the transform.position equivalent of that, I would be very grateful. Thanks!

Comment
Add comment · Show 1
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 Hellium · May 15, 2018 at 06:33 PM 0
Share

If you have installed it with the Unity editor, you can find the offline documentation here:

 <path_to_unity_editor>\Editor\Data\Documentation\en\ScriptReference

2 Replies

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

Answer by Eno-Khaon · May 15, 2018 at 06:30 PM

Where transform.position will give you the current position of a GameObject as a Vector3, transform.rotation will give you the current rotation as a Quaternion.

To clarify, Quaternion.identity is the definition for a baseline orientation. When the object has received no rotation, it still needs *something* to define its orientation. Unlike the Euler Angle representation of a rotation, you won't have a "zero" Quaternion.

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 TheEmeraldRuby · May 15, 2018 at 06:41 PM 0
Share

@$$anonymous$$o-$$anonymous$$haon I just want to know how to instantiate a prefab of which the transform.position is not 0, 0, 0. Say I made a prefab and set its transform.position.y to be... say... 2.25. I then write Instantiate(Object, new Vector3(0, 2.25f, 0), Quaternion.identity);. But then, I set the prefab's Y position to be 1.63. How would I use I kind of Quaternion.Euler for transform.position to let the game know how high to spawn the object? Sorry if something like this wasn't apparent at first.

avatar image Eno-Khaon TheEmeraldRuby · May 15, 2018 at 11:45 PM 0
Share

If you create a prefab with a position built into it and want to instantiate it at that position, you can easily use that:

 // C#
 
 public GameObject objectPrefab;
 
 // ...
 
 // Example using Start function
 void Start()
 {
     // Use the prefab's position and rotation
     Instantiate(objectPrefab, objectPrefab.position, objectPrefab.rotation);
     
     // Override the prefab's coordinates (with zero-coordinates)
     Instantiate(objectPrefab, Vector3.zero, Quaternion.identity);
     
     // Provide an offset to the stored values
     Instantiate(objectPrefab, objectPrefab.position + (Vector3.up * 1.63f), objectPrefab.rotation * Quaternion.AngleAxis(30.0f, Vector3.up));
 }
avatar image
0

Answer by Deathdefy · May 15, 2018 at 06:01 PM

Are you referring to a Vector3?

rotation is of type Quaternion and position is a Vector3. You could say the same thing for euler angles. If this isn't what you are referring to you'll have to add some more information to clarify exactly what you mean.

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 TheEmeraldRuby · May 15, 2018 at 06:23 PM 0
Share

@Deathdefy I mean how would I instantiate a prefab with it's known offset position? Just like Quaternion.identity holds its known rotation... I think.

avatar image Deathdefy · May 16, 2018 at 07:06 PM 0
Share

Yea this question completely changed after my comment lol.

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

86 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

instantiated GameObject Prefab jumps in air after instantiate 1 Answer

problem spawning bullets in c# 2 Answers

Why is transform.position of a prefab that's been instantiated different than a gameobject created on the scene, when they are in the exact same position? 1 Answer

prefab always instantiates at 0.0.0 1 Answer

Not able to fire projectiles at mouse position 2 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