Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Instantiate/Clone object same position

Discussion in 'Scripting' started by Kardes, Mar 9, 2022.

  1. Kardes

    Kardes

    Joined:
    Jan 2, 2016
    Posts:
    1
    There is a cannonball in the game and as you press the button, it sends three balls that go in sequence, then the number of balls doubles when passing through the place where it says "2X". The problem is that the doubled balls, the cloned balls, travel in different positions. What I want is; cloned balls follow the balls from which they were cloned.
     
  2. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    3,923
    Well, if you instantiate multiple objects at the same position or at positions where they overlap, they would collide with each other and seperation forces would be applied to all of them which may push them off into various directions. You essentially have two possibliities:

    • Make sure you space them out far enough so they never overlap or bump into each other.
    • Or disable the collision between your cannonballs using layermasks.
    The second option is usually the better one, though it depends on your game design. When you disable collision between the cannonballs, it means they can simply fly through each other without affecting each other. Of course that means the cannon balls need to be placed on a seperate layer. You can choose which layer can callide with which other layers in the physics settings in the layer collision matrix. You would still allow the cannonballs to collide with your targets / enemies / player / whatever but you would disable collision between objects in the cannonball layer. If you have a lot of cannonballs active at the same time, this can also increase performance.