Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 code-blep · Jul 01, 2012 at 04:14 PM · collisiontimescale

OnTriggerEnter and transform.localScale with Time.deltaTime problem

Hi,

I feel I am close to understanding this but can't quite nail it.

I have a OnTriggerEnter (bulletCollision:Collider) function. Inside that function I am trying to scale a gameObject using Time.deltaTime.

What happens is that the object instantly scales but not over time.

I now know that Time-deltaTime should happen in a function Update().

However, I am having difficulty in working out how to do this.

Here is an example of code I started with:

 function OnTriggerEnter (bulletCollision:Collider)
 {
     //Detect Collision
     if(bulletCollision.gameObject.name == "Bullet(Clone)"){
     
     GameObject.Find("TargetCube(Clone)").transform.localScale += Vector3(10,10,10) * Time.deltaTime * 10;

 
     }
 }

}

After researching I have moved on to turning the scale I want to do into a Function so that I could get it to work by some how calling it in a function Update():

 function OnTriggerEnter (bulletCollision:Collider)
 {
     //Detect Collision
     if(bulletCollision.gameObject.name == "Bullet(Clone)"){
     
     TargetCubeDeathAnim ();

 
     }
 }

}

 function TargetCubeDeathAnim () {
     GameObject.Find("TargetCube(Clone)").transform.localScale += Vector3(10,10,10) * Time.deltaTime * 10;

}

But I still can't work out how to try and get the scale change work in a function Update(). Any ideas?

Thanks

Paul

Comment
Add comment · Show 2
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 whydoidoit · Jul 01, 2012 at 05:26 PM 0
Share

So to be clear you want it to scale to the same amount, but start that scaling when it hits the trigger? Not keep scaling when it is in the trigger?

avatar image code-blep · Jul 01, 2012 at 06:08 PM 0
Share

Yes, that's it whydoidoit. I want to scale to a certain size over a few sceonds.

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by whydoidoit · Jul 01, 2012 at 06:25 PM

So you are only doing 1 scale at the moment - it's probably going to be a bit too big when you use this code because you are applying it the way you are, so adjust this to work for you.

 function OnTriggerEnter (bulletCollision:Collider)
 {
     //Detect Collision
     if(bulletCollision.gameObject.name == "Bullet(Clone)"){
 
     yield TargetCubeDeathAnim ();
 
 
     }
 }

 function TargetCubeDeathAnim () {
     var time = 5; // 5 seconds
     var go = GameObject.Find("TargetCube(Clone)");
     while(time > 0)
     {
          go.transform.localScale += Vector3(10,10,10) * Time.deltaTime * 10;  // It will get a lot bigger now!
          time -= Time.deltaTime;
          yield null;
    }
 }
Comment
Add comment · Show 7 · 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 code-blep · Jul 01, 2012 at 07:25 PM 0
Share

Thanks for looking at this $$anonymous$$ike. I'm getting ECU0001: ';' expected. Insert a semicolon at the end. Here is the line it is refering to:

yield return TargetCubeDeathAnim ();

avatar image whydoidoit · Jul 01, 2012 at 07:29 PM 1
Share

drop the return

avatar image code-blep · Jul 01, 2012 at 07:40 PM 0
Share

Hi $$anonymous$$ike, I just tried that, but get unknown identifier: 'WaitForNextFrame'.

should that be WaitForEndOfFrame ?

avatar image whydoidoit · Jul 01, 2012 at 07:45 PM 1
Share

Oh yeah - duh...

avatar image whydoidoit · Jul 01, 2012 at 09:44 PM 1
Share

Sorry, just saw this! Yeah you would probably want quite small values as it is going to be the total over the period of 5 seconds...

Show more comments
avatar image
1

Answer by Eric5h5 · Jul 01, 2012 at 05:29 PM

OnTriggerEnter can be a coroutine, do the scaling over time in there. No need for Update, it will just complicate things.

Comment
Add comment · Show 2 · 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 code-blep · Jul 01, 2012 at 06:11 PM 0
Share

Thanks Eric5h5. I'm off to research coroutines. Will get back to you as soon as I have investigated which should be in the next hour or so.

avatar image code-blep · Jul 01, 2012 at 06:18 PM 0
Share

Just tried coroutine (which looks very useful! and thanks for that!) but got the same result. The gameObject instantly scales up to the required size, and does not scale up over time.

To use coroutines I use yield functionnamehere(); yes?

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.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Timecale=0 stops joystick. can it not? 1 Answer

Problem with finding the right syntax for time. 1 Answer

Detecting When Intersection Penalty is Being Applied 2 Answers

How to get the correct ratio of collision distance to total scale? 1 Answer

Time freeze 1 Answer


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