• 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 /
avatar image
0
Question by Ninamori · Nov 02, 2015 at 03:39 PM · c#rigidbodyrigidbody-collision

Trigger activating before entering trigger. What do I do?

Code:

 using UnityEngine;
 using System.Collections;
 
 public class Switch : MonoBehaviour
 {
     GameObject Ball;
 
     // Use this for initialization
     void Start()
     {
 
     }
 
     // Update is called once per frame
     void Update()
     {
 
     }
 
     void OnTriggerEnter(Collider coll)
     {
         if (coll.gameObject.tag == "Ball")
             Debug.Log("Ball Entered! :)");      
             
     }
 
 }

I have two objects. A ball, and a box. When the ball enters the box (which is marked as a trigger) it should do something (in this case send a message to me in console). Problem being is that it is activating before it ever hits the trigger. What do I do?

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 OncaLupe · Nov 02, 2015 at 05:13 PM 0
Share

Is there any consistent behavior to when it's triggering? Such as randomly, only when you're moving toward it from a certain distance, etc?

Check the collider of the box (should show as a green outline when it's selected) and make sure it isn't somehow set larger than it should be.

avatar image van der Merwe · Nov 02, 2015 at 08:50 PM 0
Share

@Ninamori As OncaLupe suggested, have a look at the collider on the box and make sure it is not to large, do the same with the ball game object. Maybe the ball has a larger collider.

You can also have a look in the scene rather then the game play when you start. The script has no errors or not that I can gather.

0 Replies

· Add your reply
  • Sort: 

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

A script that doesn't allow moving objects to go through non-moving objects? 1 Answer

Stopping Moving Objects? 0 Answers

Why is new Vector3 stronger when player is in the air? 0 Answers

How to get all child Colliders as single Collider 1 Answer

Why is my Rigidbody freaking out like this? 0 Answers

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