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

Scale changes with parenting/de-parenting/re-parenting

Discussion in '2D' started by MoonJellyGames, Sep 2, 2015.

  1. MoonJellyGames

    MoonJellyGames

    Joined:
    Oct 2, 2014
    Posts:
    331
    Hi all. I'm having some weird scaling problems with the stickybombs in my 2D multiplayer platformer game. It's difficult to replicate the bug consistently, but it happens often enough that it's a huge problem. Basically, when you press R1 (I'm using DS3 controllers), your player pulls out a bomb. The bomb is an instantiated as a clone of a bomb prefab, and the parent of the bomb is set to the transform of the player.

    When you throw a stickybomb, the bomb's parent is set to null to detach it from the player. This alone is not problematic. The trouble comes with the "sticking". See, after a stickybomb is trown, if it comes in contact with the stage or another bomb (using OnCollisionEnter()), the bomb is set to kinematic, velocity is set to zero, and (in an attempt to correct the scaling problem) the local scale is set to (1,1,1). If a stickybomb comes in contact with a player (using OnTriggerEnter because players don't actually use Unity's physics), the same things happen plus the player is set as the parent.

    The scaling problem seems to happen when the player with a bomb stick to them is facing left when the bomb explodes.

    There's a little more to it, but I don't want to make this longer than it needs to be. It seems to just be a problem with the player's x-scale flipping from 1 to -1 which I've read about, but I haven't found any good solutions. There are a number of key places where the local scale is set to (1,1,1), but it just doesn't cut it consistently.

    Is there a better way to do stickybombs? They need to stick to the part of the player that they hit, and also be able to stick to another player to rub the bomb off.

    Any help or suggestions would be appreciated. Thanks!
     
    Last edited: Sep 2, 2015
  2. leoyaik

    leoyaik

    Joined:
    Oct 13, 2014
    Posts:
    6
    One possible way would be by having a parent to the actual object.

    PlayerGO (translation and rotation goes here)
    - ActualPlayerGO (scaling goes here)
    - AttachedStickyBomb

    This way, the 'sticky bomb' scale won't get affected by the object it is attached to.