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
0
Question by Dothackking · Jul 13, 2013 at 06:26 PM · c#trigger

OnTriggerStay only happens when I move?(c#)

I'm having problems where instead of "every frame" my updating for certain things is only happening when I move. For instance:

 void OnTriggerStay(Collider col)
 {
     if(col.tag == "player")
     {
         tooltips.text = "Weapon type: " + currentWepType + "\n Weapon damage: " + dmg.ToString() + "\n Attack speed: " + aspd + " attacks per second";
     }
 }

and

     if(col.tag == "weaponEquipped")
     {
         wepDmg = col.GetComponent<Item>().dmg + Mathf.FloorToInt(skillDisplay);
         wepSpd = col.GetComponent<Item>().aspd;
         if(col.GetComponent<Item>().currentWepType == "1h sword")
         {
             currentWeaponType = "1h sword";
             skillType = "swordSkill";
             skillDisplay = swordSkill;

         }
         else if(col.GetComponent<Item>().currentWepType == "2h sword")
         {
             currentWeaponType = "2h sword";
             skillType = "twoHandSwordSkill";
             skillDisplay = twoHandSwordSkill;
         }
         else if(col.GetComponent<Item>().currentWepType == "axe")
         {
             currentWeaponType = "1h axe";
             skillType = "axeSkill";
             skillDisplay = axeSkill;
         }
         else
         {
             currentWeaponType = "unarmed";
             skillType = "unarmed";
         }
     }

Neither of those update until I take a step. If this is intended, is there any similar function I can use to OnTriggerStay that updates every frame like Update()?

Comment
Add comment · Show 1
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 creighcl · Jul 15, 2013 at 04:51 PM 0
Share

I've noticed similar behaviors. For triggers and collision detection, these operations aren't triggered unless there has been a change in the position of one of the rigid bodies involved otherwise these rigid bodies will 'sleep'

1 Reply

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

Answer by supercouge · Jul 13, 2013 at 09:12 PM

I had a similar problem with OnTriggerStay().

Just to be sure, did you check with the Debug.Console, that OnTriggerStay wasn't called? If you have checked that OnTriggerStay wasn't called, then in your Update() function add this line:

 void Update() {
   transform.position = transform.position + Vector3.zero;
 ]

Back then, this had solved my problem. However, I'm not sure why this problem happens.

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 Dothackking · Jul 13, 2013 at 09:24 PM 0
Share

Weird, i just checked, and until I start moving, it doesn't update the triggerStay to include the newly changed tag.

Your solution worked, but I assume that would be really inefficient use of processing power.

avatar image supercouge · Jul 13, 2013 at 09:31 PM 0
Share

I agree, but I don't managed to found another way. :/

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

18 People are following this question.

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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Can requirecomponent specify IsTrigger on a collider? 1 Answer

Mobile Input Touch Tag Unaffected 0 Answers

How Activating a boolean fron another script(C#) 1 Answer

Trigger GUI with a key when colliding (C#)? 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