Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Put Object on a random position of the BoxCollider

Discussion in '2D' started by S4nikrA, Jun 16, 2023.

  1. S4nikrA

    S4nikrA

    Joined:
    Jun 16, 2023
    Posts:
    3
    Hey guys!
    For the idea:
    I want to hit an enemy, which goes on top of my player in the range of the BoxCollider from player. The BoxCollider should be increased, so the player + enemy on my player getting a new BoxCollider.
    My Goal is a chunk of the player with many enemies on it. (I drew something, maybe this helps)

    Do you guys have any ideas how to solve this problem?

    Thank you!
     

    Attached Files:

  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,563
    Do you mean you want to stick them together when they hit??

    You can simply parent them to the player.

    If you're using physics, attach the child to the parent with a joint of some kind.
     
  3. S4nikrA

    S4nikrA

    Joined:
    Jun 16, 2023
    Posts:
    3
    Not directly. I don't want to stick the enemy on a side of the player, either I want it on my player as complete new object. I don't know, if a joint could help me here
     
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,468
    This isn't clear at all.

    Again, I cannot follow what it is you want here.

    You image just shows things overlapping so I'm not sure what the behaviour is you want.
     
  5. S4nikrA

    S4nikrA

    Joined:
    Jun 16, 2023
    Posts:
    3
    I want to stick them together. But everytime I collect an enemy, he stick on a random position of the player. This thing should be the new player. When I repeat this process, I want a chunk with a huge player, when I collected many enemies.

    So far I calculated the players size (it's a square) and want to put the enemy on a random position onto the player. But I just don't know how to stick the enemy to the player.
     
  6. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,468
    You'll need to be specific. What is an "Enemy"? Presumably the "Enemy" becomes part of the "Player"? So if by "Enemy" you mean a SpriteRenderer2D and its Collider2D then add it as a child to the "Player" and remove any other components you don't need when it's no longer an "Enemy". Don't add the "Rigidbody2D" of the "Enemy" though, this way the "Enemy" collider will be attached to the "Player" Rigidbody2D. You don't need to recreate colliders etc.

    Again, if this is wrong, you need to be more specific beyond "Player" and "Enemy" if you need a specific solution.

    "Stick" - Physically based connection or just fixed exactly to the "Player" via the Transform?
    "Player" - What is this composed of?
    "Enemy" - What is this composed of?