Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
This question was closed Dec 13, 2016 at 12:31 PM by Brylos for the following reason:

Other

avatar image
0
Question by Brylos · Dec 11, 2016 at 04:21 PM · networkingtrigger

Help with trigger detection?

Hi there. I'm trying to have a trigger detect if a ball is in it's trigger zone. The values don't seem to be changing as they should accordingly. It is on UNET but only the local player needs to know if it is triggered or not. I mention that it's on UNET just in case something related to it is causing the issue. If the issue doesn't stem from UNET, I think it maybe that I'm not referencing the box collider properly. The trigger checkbox is checked on it. The way I'm doing it is having a script attached to the gameobject with the trigger collider, and then having my playercontroller script reference if it is triggered or not, then setting a float number to 1 if it is triggered, 0 if it's not. I was trying to see if [Command] would work for the OnTriggerEnter() and OnTriggerExit() voids but I couldn't get it working(I probably just coded it incorrectly if that is where it is going wrong).

Here's the script that is attached to the object with the collider:

 ///////////////////////////////////////////
     public static float Triggered;
 
     void OnTriggerEnter(Collider Trigger)
     {
         if (Trigger.gameObject.CompareTag("Ball"))
         {
             Triggered = 1;
         }
         else
         {
             Triggered = 0;
         }
     }
 
     void OnTriggerExit()
     {
         Triggered = 0;
     }
     ///////////////////////////////////////////

Here's the Reference to it in my playercontroller script:

 //HitboxDetection
         if (Hitbox.Triggered == 1)
         {
             IsTriggered = 1;
         }
         else if (Hitbox.Triggered == 0)
         {
             IsTriggered = 0;
         }
         if (IsTriggered == 1)
         {
             Debug.Log("CanPass");
         }

Does anyone have an idea of what I'm doing wrong? Thanks in advance.

Comment
Add comment · Show 3
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 Pengocat · Dec 11, 2016 at 05:11 PM 0
Share

Comparing floats can be tricky so you should use a bool or int ins$$anonymous$$d.

avatar image Brylos Pengocat · Dec 11, 2016 at 05:24 PM 0
Share

I switched it to an int but it still isn't working.

avatar image hexagonius Brylos · Dec 11, 2016 at 07:42 PM 0
Share

you should check if you even get the trigger calls correctly and then take the networking step, one at a time.

1 Reply

  • Sort: 
avatar image
0

Answer by michelle12188 · Dec 11, 2016 at 11:18 PM

Do you have a rigidbody on either the trigger or the ball? If not add one.

from the unity docs:

Trigger events are only sent if one of the Colliders also has a Rigidbody attached.

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 Brylos · Dec 12, 2016 at 05:24 AM 0
Share

Yes there is a rigidbody attached to the ball.

avatar image michelle12188 Brylos · Dec 12, 2016 at 05:57 AM 0
Share

Is it not recognizing the trigger function at all or is it never recognizing the tag? A thing to note as well is that a default for an int is 0 so you won't see a change in the triggered if it is going to the else statement/OnTriggerExit(). I would suggest a few debugs so you can tell in the Console while you're trying to solve it.

avatar image Brylos michelle12188 · Dec 12, 2016 at 06:46 AM 0
Share

I used debut.logs in both the OnTriggerEnter void and in the if statement that's in the OnTriggerEnter void. The only time either showed up in the console was as soon as I started a server and it was only the one for the void, not the if statement. I tried having multiple objects enter the trigger but still nothing. So that tells me it's the OnTriggerEnter, not the tag. One thing to consider is that the collider trigger and the script are on a child object of my playerprefab. $$anonymous$$aybe it can't access it? Is there a way to assign the trigger via a public Collider then just drag it onto the slot. $$anonymous$$aybe that will work.

Here's the the script again:

 ///////////////////////////////////////////
     public static int Triggered;
 
     void OnTriggerEnter(Collider Trigger)
     {
         Debug.Log("TriggerDetectsObject");
         if (Trigger.gameObject.CompareTag("Ball"))
         {
             Debug.Log("TriggerDetectsBall");
             Triggered = 1;
         }
         else
         {
             Triggered = 0;
         }
     }
     void OnTriggerExit()
     {
         Triggered = 0;
     }
     ///////////////////////////////////////////
Show more comments

Follow this Question

Answers Answers and Comments

119 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 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 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 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 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 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

Transform.find Does not work 0 Answers

How to prevent other players from activating triggers for all players? 0 Answers

Sync Mecanim Trigger over network 1 Answer

Trigger on player controller prefab not working? 0 Answers

Make trigger event can be observe in multi player (photon)? 2 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