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 Deikkan · Jul 10, 2010 at 03:44 PM · collidertrigger

Trigger collider triggers even though colliders are not touching

I currently have a trigger collider set up on a weapon, and when it touches an enemy character controller, sends the "DealDamage" method. However, the trigger seems to get activated even when the weapon is nowhere near the enemy. The code I have is below:

var damage : int; private var nextFireTime = 0.0; var reloadTime : float= 0.5; var distanceto : float;

function OnTriggerEnter (other : Collider) {

 if(other.gameObject.tag == "Enemy" && PlatformerPlayerAnimation.isAttacking
 && Time.time > nextFireTime)
 {
 distanceto = Vector3.Distance(gameObject.transform.position, other.gameObject.transform.position);
 print(distanceto);
 nextFireTime = Time.time + reloadTime;
 print("hitboss");
 other.gameObject.SendMessage ("DealDamage", damage);
 }

When the trigger gets activated, it prints the distance between the two gameobjects so I can make sure that they are definately not touching. I can get it so that "hitboss" gets printed even though the distance is at least 30 (bigger than the colliders themselves).

Any help?

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 Tetrad · Jul 10, 2010 at 05:45 PM

I would suggest doing something like this:

function OnTriggerEnter (other : Collider) {

 if(other.gameObject.tag == "Enemy" && PlatformerPlayerAnimation.isAttacking && Time.time > nextFireTime)
 {
     distanceto = Vector3.Distance(gameObject.transform.position, other.gameObject.transform.position);
     print(distanceto);
     if( distanceto > 30 )
     {
         Debug.LogError( "Collison occured when too far away?", this );
     }
     nextFireTime = Time.time + reloadTime;
     print("hitboss");
     other.gameObject.SendMessage ("DealDamage", damage);
 }

}

And then turning on "error pause" in the console. When your situation happens, it'll pause the game on that frame, and you can see exactly where the thing with the collider is in the world (if you double click on the error in the console it'll highlight the game object in the scene.

Also, try some other strategies here: http://answers.unity3d.com/questions/13827/my-script-isnt-working-what-are-some-ways-i-can-start-debugging

Comment
Add comment · Show 1 · 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 oldsoldier · Nov 05, 2012 at 08:47 PM 0
Share

Hey thank you Jesse this helped me too, you're a boss man!

avatar image
0

Answer by Ashkan_gc · Jul 10, 2010 at 03:59 PM

you might set the tag of the main player to Enemy by accident! check the tag of your main player or just add another condition that checks if the instanceID of the object that we are colliding with is different from the parent of the weapon.

Comment
Add comment · Show 1 · 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 Deikkan · Jul 10, 2010 at 04:45 PM 0
Share

Thanks, but I dont believe that is a case. I have a bit of code that finds all the gameobjects with the tags marked 'Enemy' and prints them to the console, the only thing it returns being the actual enemy. I'll keep messing with it and see if I get an answer.

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

1 Person is following this question.

avatar image

Related Questions

Can't click gameobject when over another trigger? 1 Answer

Unity 2D Trigger Detection is not working. 6 Answers

OnTriggerEnter mesh collider problem 1 Answer

Enemy line of sight using linecast and colliders 1 Answer

GameObject Parent & Child Visibility 0 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