• 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 Therian13 · Feb 23, 2015 at 05:30 AM · timeontriggerenterdelayslow

On Trigger Enter no longer works? long delay to activate

Hello Everyone,

My game is a 3D game. Earlier, I had a basic repair script attached to a gameobject. Whenever I swing my repair hammer, it turns on it's collider and if it something with the tag "repairable" it would then do a "theCollider.transform.SendMessage ("ApplyHeal", TheRepair, SendMessageOptions.DontRequireReceiver);"

I then noticed that my other onTrigger functions are doing the same, such as an arrow or bullet doesn't collide with the wall when it hits, unless I'm very far away. If I get to close, it just passes through the object like it doesn't exist.

It seems to have started since my last Unity update, but I doubt that it the cause.

Would anyone be able to point me in the right direction on what is going on?

I apologize for the vagueness, but I can't really pinpoint what the problem is, aside from the On Trigger is working much slower if at all.

I tried changing the fixedTimeStep and such, but it doesn't seem to help.

Thank you for your time.

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

2 Replies

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

Answer by Therian13 · Feb 23, 2015 at 09:07 AM

I finally found out what was causing it. It was REALLY weird, but for some reason my physics manager had it that anything on my draw layer (in this case my arms and hammer) couldn't hit anything layer Default (the repairable objects)

But good news is I got it fixed! Still no idea how that happened. I haven't touch the physics manager in months... 0_o

But thank you everyone for your help! :D

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
1

Answer by skylem · Feb 23, 2015 at 06:07 AM

i've experienced similar issues with triggers and colliders sometimes to fix these u can change the rigidbodys collision detection to continuous, if this doesn't help you maybe you change some of your system to be a raycast, as for your trigger delay i can't be sure of the cause but if i were to speculate i would have to wonder how much information your script processes before doing something with the trigger i'll provide a couple of my own methods for using triggers to define an object for interaction and also a simple raycast that i use to loot items which should be easy to adapt for alot of cases such as shooting bullets.

 this is my method for assigning an interactable object. u can place this on any object that has a trigger.
 
     void OnTriggerEnter(Collider Other){
         if (Other.gameObject.tag == "Player") {
             PlayerInteraction pit = Other.GetComponent<PlayerInteraction>();
             if(pit.interTarg == null) {
                 pit.interTarg = gameObject;
             }
             if(pit.interTarg != null) {
                 pit.nextTarg = gameObject;
             }
         }
     }
     void OnTriggerExit(Collider Other){
         if (Other.gameObject.tag == "Player") {
             
             PlayerInteraction pit = Other.GetComponent<PlayerInteraction>();
             if(pit.interTarg == gameObject && pit.nextTarg != null) {
                 pit.interTarg = pit.nextTarg;
                 pit.nextTarg = null;
             }
             if(pit.interTarg == gameObject && pit.nextTarg == null) {
                 pit.interTarg = null;
             }
         }
     }
 }
 
 // a brief breakdown of how it works this assumes that the Player has a script called PlayerInteraction upon this PlayerInteraction script there is 2 GameObject Variables one named interTarg, which is the current target for interaction. and nextTarg ,this is for if we manage to stand on 2 triggers simaltanously.
 and note that you will never need to make changes to the above
 since u will be doing everything with these Interactions within your PlayerInteraction a simple example to be used in playerinteraction below.
 
 // first checking if we have a target of interaction.
 if(interTarg != null) {
     // this is where would check information regarding the target
     // before we do something to it
     if(interTarg.tag == "Shop") {
         showShopGUI = true;
 }
 }
 // then i would go on to use that bool for some GUI display.
 
 // Forward Raycast from our cam, hit represent the impact point of the ray
 // i use it below to see if we hit a transform then check the name of that transform
 // before accepting an input key to pick the item up
         RaycastHit hit = new RaycastHit ();
 /// uncomment below to see the raycast in the scene.
         //Debug.DrawRay (GetComponentInChildren<Camera>().transform.position, GetComponentInChildren<Camera>().transform.forward * 3f, Color.blue, 1f);
         Physics.Raycast (GetComponentInChildren<Camera>().transform.position, GetComponentInChildren<Camera>().transform.forward * 3f, out hit, 15f);
         if(hit.transform != null && hit.transform.tag == "Loot") {
 
             if(Input.GetKeyDown(Keycode.E)) {
                 LootItem(hit.transform);
             }
         }

// if i was unclear on anything or u need help understanding something i didn't cover feel free to email me Skylem@live.com.au appologies for the long winded answer, i did my best to only include information relevant to a possible solution

Comment
Add comment · Show 4 · 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 Therian13 · Feb 23, 2015 at 06:31 AM 0
Share

the scripts are fairly simple. just your basic onTrigger enter(theCollider : Collider) if (the collider.tag == "something" Send the damage;

The hammer doesn't have a rigidbody on it, however it is parented to the character which does have one. It used to work just fine, but just seemed to stop.

I can't use raycast, because the parts you repair are childen of another gameobject, and the raycast seems to only hit the main parent, regardless of what I target (which in itself is strange).

avatar image skylem · Feb 23, 2015 at 08:28 AM 0
Share

ah well i can only guess as to what might have caused it to stop working all of a sudden, have u made changes to physics collision/layers since they were working?, as for the raycast hitting parented objects, u can access children objects with the following i don't know if its applicable to your situation but heres the code.

     transform.GetChild(0); // 0 represents the first child object
     // also u can use 
     if (transform.childCount > 0) 
     // to determine wether the object has any children. 
     
     //i also use the following if i want to specify a child object to find using its name
 
      // transform.FindChild("9$$anonymous$$$$anonymous$$Pistol");
 

hopefully this can help.

avatar image Therian13 · Feb 23, 2015 at 09:08 AM 0
Share

although your thing wasn't what was wrong with my scene, I went ahead and did an "UP" since you gave some really good feedback.

Thank you! :D

avatar image skylem · Feb 23, 2015 at 10:01 AM 0
Share

no problem, the amount of ways u can achieve a desired affect are so varied its almost overwhelming, i find that sharing different examples is as good a way as any to remember these techniques, even if they aren't always valid to the current issue odds are you'll find them useful in the future, Good luck with your future scripts (y).

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

20 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 avatar image avatar image

Related Questions

weapon bobbing 1 Answer

[c#] How can I let something happen after a small delay? 7 Answers

How to delay animation after OnTriggerEnter?? 2 Answers

How to make an enemy respawn? 0 Answers

Autodetect new assets on Mac takes a minute 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges