• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by jammerjar · Jun 15, 2011 at 09:54 AM · localscaleincrement

Help me put air in my balloon!

Hi - I'm working on a project where I want to create an instance of a balloon and then have that inflate after it is created. Got the instance working but want to add the inflation. I'm guessing I use transform.localScale for this but can see how I make this incremental.

Help me put air in my balloon so i don't feel so deflated. :-(

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by DayyanSisson · Aug 18, 2011 at 06:29 AM

I think the easiest way (isn't very efficient) is making an animation of it inflating, and making that appear when the ballon starts to inflate. This might not help you, but it's better than nothing. Hope this helps :) and happy game making.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by save · Jun 15, 2011 at 10:22 AM

Make sure the pivot of your balloon model is at the actual intake (end):

Yes this is a balloon's intake nothing else

If it's a detailed object you can switch the model from deflated to full round (inflated) when the inflation starts.

To expand size of something you'd need a variable that changes over time, something like this perhaps (not tested):

     var inflateMe : boolean = false;
     var airAmountMax : float = 5.0;
     var airAmountMin : float = 1.0;
     var speed : int = 2;
     
     function Update () {
     if(inflateMe)
         transform.localScale = Vector3.Lerp(transform.localScale, airAmountMax, Time.deltaTime * speed);
     } else {
         transform.localScale = Vector3.Lerp(transform.localScale, airAmountMin, Time.deltaTime * speed);
     }
 
     function inflation () { 
         if(!inflateMe){
             inflateMe=true;
         }else{
             inflateMe=false;
         } 
     }

Then when you call balloonObject.GetComponent(balloonScript).inflation(); from another script the inflation/deflation starts.

If you just want it to inflate at start you can just basically use:

 function Update () {
     transform.localScale = Vector3.Lerp(transform.localScale, theSizeYouWant, Time.deltaTime * theSpeedYouWant);
 }

Also have a look at the Mathf-functions to control changes with lerp or smoothing over time. If you don't use Vector3 to alter x-, y- and z-scale you'll need to change one (x for instance) with a Mathf-function and just set the rest to match that value (transform.localScale.y = transform.localScale.x;).

Hope it helps!

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image jammerjar · Jun 15, 2011 at 06:55 PM 0
Share

That sounds brilliant and I sort of understand it too! Ha Ha no really what i don't get is the boolean false. Im looking to inflate this when it is triggered by a user action and thought the best way to do that wold be thru Input.GetDownButton. So sorry if this is really obvious but how d i use that with boolean? Otherwise I cant wait o give this a go but got to go to work right now. Thanks.

avatar image save · Jun 15, 2011 at 07:45 PM 0
Share

You could trigger the event by user input and better off attach the script at runtime to the GameObject (for instance if you have 100 balloons this would be better).

Have a look at Raycasts (search here for "mouse gameobject clicked" for instance) and AddComponent, then put my second script in a separate script which you add with GameObject.AddComponent. To later make them fly away attach a rigidbody at the same time and give constant force in the upward vector.

If you don't know how to use booleans then I'd suggest you'd do some reading: http://unity3d.com/support/documentation/ScriptReference/index.html

Good luck mate!

avatar image jammerjar · Jun 17, 2011 at 09:36 PM 0
Share

Hi again - I have been working away at the script you posted and think I have a handle on how it works but cant get it to debug. Hope you don't $$anonymous$$d giving me yet another hand here. The issues seems to be when the function inflation is declared. But I can for the life of me see why it wont accept this code. $$anonymous$$uch appreciate your help if you have time.

avatar image
1

Answer by Tom 17 · Jun 15, 2011 at 10:07 AM

Funny head line, captivated me!

you could store the time when the inflation starts like that:

float startTime = Time.time;

and when you inflate over time you can do something like this in the Update() method:

float factor = 1.0 + (Time.time - startTime) * 0.01; // 0.01 is an arbitrary factor, experiment with it

transform.localScale = new Vector3(factor , factor , factor );

that should inflate your balloon. I hope that makes you a happy kid. Go out and play ;-)

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Tom 17 · Jun 15, 2011 at 10:09 AM 0
Share

btw this is C# code, I think if you change "float" for "var" and leave out the "new" you have JavaScript code..

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Using transform.localScale to flip object 1 Answer

How to get expanding object collide when it touches others? 1 Answer

How to use WaitForSeconds inside IF / Else If statement? 1 Answer

transform.localScale.x - can't change it 1 Answer

rigid body can rotate but will not move 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges