0

Below is part of my collision script, everything is working fine with it.

I am trying to figure out how to make "player" do a smooth rotation and shrink the scale of the player object. How would I go about this? Should I create a check variable and check in update method to do a smooth rotation and I have no clue about smooth scale shrinking. Any help on how to go about this would be appreciated.

if(blackholeActive == true){
        player.transform.Rotate(new Vector3(0, 0, Time.deltaTime * -150));
        player.transform.localScale = Vector3.Lerp(transform.localScale, new Vector3(0.025f, 0.025f, 0.025f), 0.01f * Time.deltaTime);
    }


// Black Hole Collision
    if (col.gameObject.tag == "BlackHole")
    {
        Debug.Log("Black Hole");
        int valC = coinCount;
        //coinCount = 0;
        int valS = starCount; // for stars lost text
        //starCount = 0;

        //Stop player from moving and falling and make them disappear into blackhole
        player.transform.GetComponentInChildren<Rigidbody2D>().bodyType = RigidbodyType2D.Static;
        player.GetComponentInChildren<Rigidbody2D>().velocity = Vector2.zero;
        player.GetComponentInChildren<Rigidbody2D>().gravityScale = 0;

        /// TODO: Stop Blackhole movement
        /// Make player spin and shrink
        blackholeActive = true;

        coinsLost.text = "Coins Lost: " + valC;
        starsLost.text = "Stars Lost: " + valS;
        gameOverCanvas.gameObject.SetActive(true);

    }
shane
  • 342
  • 1
  • 5
  • 28
  • The code you posted is not doing any rotation or scaling.. – Programmer Aug 01 '18 at 19:58
  • I see lerp as one of your tags so have some idea of what you want, a quick google search will show a lot of quaternion lerp answers and transforming localScale using lerp – comphonia Aug 01 '18 at 20:09
  • Ok, I updated the post. The if statement is in my update function. However, the shrink doesn't work like I thought it would. It either shrink the object way to fast or isn't shrinking how I thought it would. @Programmer – shane Aug 01 '18 at 20:16
  • Has to be multiplied by `Time.deltaTime * speedVarriable` not just `Time.deltaTime`. The `speedVarriable` variable should just be a public `float` you can modify until you like the speed. If you know the rotation and scale you're moving to then use coroutine. – Programmer Aug 01 '18 at 20:22

0 Answers0