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

How to make 2D basketball game throw?

Discussion in '2D' started by unity_rzQSwUvJF1UZXQ, Dec 30, 2020.

  1. unity_rzQSwUvJF1UZXQ

    unity_rzQSwUvJF1UZXQ

    Joined:
    Oct 28, 2020
    Posts:
    10
    Hi! I am starting a new project but I am a bit confused about the game I used as a reference.
    I dont understand if it is 3d, 2d or 2.5d.
    I think it is 2d but, in that case, how did they make that depth effect
    making the ball smaller the further?¿How did they thow a 2d ball on z axis?

    The game I am talking about is this:
    https://www.youtube.com/watch?v=QQFqRlkxS3g



    I'd appreciate it if you could help me.
    Thanks for reading it.
     
  2. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,319
    The depth effect seems to be from decreasing the scale of the basketball once it's shot.

    Code (CSharp):
    1.  
    2. public float shrinkSpeed = 1f; // tune this to control how quickly it shrinks
    3. public float shrinkScale = .5f;
    4. bool hasBeenShot;
    5. float timeShot;
    6.  
    7. void ShootBall()
    8. {
    9.     hasBeenShot = true;
    10.     timeShot = Time.time;
    11.  
    12.     // launch it
    13. }
    14.  
    15. void Update()
    16. {
    17.     if(hasBeenShot)
    18.     {
    19.        float timeSinceShot = Time.time - timeShot;
    20.  
    21.        // lerp to go from full scale (1f) to shrinkScale (.5f)
    22.        float scaler = Mathf.Lerp(1f, shrinkScale,  timeSinceShot * shrinkSpeed);
    23.        transform.localScale = Vector3.one * scaler;
    24.     }
    25. }
    26.  
    There are a bunch of ways to accomplish the same, but the above illustrates the basic idea.
     
  3. unity_rzQSwUvJF1UZXQ

    unity_rzQSwUvJF1UZXQ

    Joined:
    Oct 28, 2020
    Posts:
    10
    Thanks for the answer! I will try handling the scale similar to that and see how it looks.