• 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 /
  • Help Room /
avatar image
0
Question by Eyanosa · Jun 14, 2017 at 08:46 AM · gameobjectspositioninginstantiate prefabpysics

Positioning a prefab correctly with Instantiate

Hi,

A couple of month ago I started programming a little FPS in Unity with a friend of mine. One of our most disturbing challenges is the correct positioning of game objects.

Lets say we position two cubes on top of each other. Each cube has its own box collider and a rigidbody. Our goal is to shoot a them and each cube works with its own physics. The two cubes are positioned directly on our playground (w$$anonymous$$ch is a large cube (10,1,10)). W$$anonymous$$le placing the two cubes manually, we don't have a problem: alt text

The problem comes when saving the cube as prefab and then instantiating one cube on top of each other. Lets say I have a Loop and instantiate first cube #1 and then instantiate the 2nd cube in my 2nd pass of the loop (y + 1). T$$anonymous$$s should position both cubes correctly....

But what happens is: The upper cube flies away....like two magnets having the same polarity.

alt text Why does t$$anonymous$$s happen? I would t$$anonymous$$nk that w$$anonymous$$le instantiating those two cubes, a collision happens and physics do the rest....

Is there a logic explanation? In our future project we will have a lot game objects on top of each other.

Thanks for any helping hands.

Best regards, Eyanosa

bubes2.png (140.4 kB)
cubes1.png (155.2 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
0

Answer by Eyanosa · Jun 15, 2017 at 12:40 PM

bump

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 jtok4j · Oct 22, 2017 at 07:31 PM

Greetings, I've noted that when I begin a scene, with the player Gameobject's collider intersects the Terrain's collider (e.g. placed the Player a little to close/slightly into the ground) then the Player flies around, upon starting the game. So, possibly, the colliders of the cubes are intersecting each other, and should be examined. Hope t$$anonymous$$s helps.

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 the_real_ijed · Jan 17, 2018 at 08:57 PM

Yes, the above post is correct - if the cubes are instantiated as touc$$anonymous$$ng then the physics system will fire them off away from each other. I'm guessing the bottom one doesn't because of the floor. Just instantiate them both a bit $$anonymous$$gher up and with a slight gap between them so they aren't touc$$anonymous$$ng each other or the floor when created.

Bear in mind t$$anonymous$$s quirk of physics engines can be a useful if you want to make an explosion of debris :)

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

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

108 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 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

How to instantiate objects to mesh while restricting the spawn area on a single axis? 2 Answers

Dynamic sorting objects on terrain 0 Answers

Prefabs aren't instantiating where they should be 0 Answers

How to make gameobject appear in center of camera irrespective of it's side?? 0 Answers

Create GameObjects and move them from JSON data 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