Hello helpful people,
I’m an animator starting from scratch with Unity so would really appreciate your help.
I’m trying to set up a sequence in which a small sphere increases in size when the player presses the up key, and deflates when they press the down key. I’d like to put a smiley face on the balloon and see it stretch outwards when inflating and all loose when deflated. Ideally the anchor point for the balloon will be at it’s lowest point, rather than scaling up from the centre. The balloon will be inside a box so I would like it to not exceed the limits of that and deform to take the shape of it if poss. Like a balloon would!
I hope this makes sense. Thank you!!
-
Add an empty game object to your scene and place it at the anchor point
-
Drag your sphere name onto the empty game object name in the hierachy panel (this makes it a child of the game object (Rename the empty game object for ease of remembering
-
Create a new java script (call it something like - Inflate)
-
In function Update() put the following:
if (Input.GetKey(KeyCode.UpArrow)){ transform.localScale += Vector3(0.05,0.1,0); } else {transform.localScale += Vector3(-0.05,-0.1,0);}
-
Drag the script from your Assets panel onto the empty game object in the hierachy panel
-
Press play – Note that it will deflate below the point you want and has no limit on how far it will inflate… but it should be enough to get you started!
Great start! Thanks.
the code above changes the size.
if you want to find a balloon shape which is kind of an upside down raindrop, you could look for one online Party Balloon in Obj Format - 3D Model - ShareCG
and to anchor it by the bottom, the best thing is to use physics -rigidbody components only in the up/down direction, or even simpler , to move the balloon object position a bit higher as it gets larger so that the top moves fast and the bottom stays in the same place.
with physics you could see if you can find some rope object in unity and apply constantforce upwards to the balloon.
there is also procedural example which changes a sphere, and that’s a fine example but it’s quite advanced, vertex algorithms.