Search Unity

How do I morph the player towards y velocity?

Discussion in 'Scripting' started by PixelRankYT, Jun 1, 2020.

  1. PixelRankYT

    PixelRankYT

    Joined:
    Jun 1, 2020
    Posts:
    1
    How can I morph/stretch the player when he jumps, falls and lands? I am using a rigidbody controller and it's a 2D game. I have been trying to find answers to this on different developer discords and on youtube and I found nothing.
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,911
    You can stretch your sprite by modifying transform.localScale:
    Code (CSharp):
    1. Vector3 currentScale = transform.localScale;
    2.  
    3. // Let's make our character twice as tall:
    4. Vector3 newScale = new Vector3(currentScale.x, currentScale.y * 2, currentScale.z);
    5. transform.localScale = newScale;
    Just a warning though, this will scale everything underneath this object in the hierarchy.