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 /
avatar image
0
Question by Chocolade · Aug 06, 2017 at 08:32 PM · c#scripting problemscript.

Why none of the events OnTriggerEnter or OnCollisionEnter not fire ?

The script is attached to a GameObject a cylinder.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class EnemyAttack : MonoBehaviour {
 
     public bool entered = false;
 
     private void OnTriggerEnter(Collider other)
     {
         if (other.gameObject.name == "Enemy")
             entered = true;
     }
 
     private void OnCollisionEnter(Collision collision)
     {
         if (collision.gameObject.name == "Enemy")
             entered = true;
     }
 
     private void OnCollisionExit(Collision collision)
     {
         entered = false;
     }
 }
 

"Enemy" is the GameObject and that should be detected once it's entering the GameObject this script is attached to.

Entering or Collide with. But it doesn't matter none of the events work. I used a breakpoint and it's never get any of the events.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by moltow · Aug 06, 2017 at 08:39 PM

Does this cylinder or the Enemy GameObject have a RigidBody attached?

Note from OnTriggerEnter docs:

Trigger events are only sent if one of the colliders also has a rigidbody attached.

Note from OnCollisionEnter docs:

Collision events are only sent if one of the colliders also has a non-kinematic rigidbody attached.

Hope this helps.

Comment
Add comment · Show 5 · 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 Chocolade · Aug 06, 2017 at 08:50 PM 0
Share

I added to the Cylinder a Rigidbody. Only the Use Gravity is checked.

But then the Cylinder start to rotate and fly in the air and move away. The only way he stay on ground is if i check also the Is $$anonymous$$inematic. And when the Is kinematic is checked none of the events work.

avatar image moltow Chocolade · Aug 06, 2017 at 09:00 PM 0
Share

You can use the restraints on the RigidBody attached to the Cylinder to prevent it from moving on you.

avatar image Chocolade · Aug 06, 2017 at 08:57 PM 0
Share

It's working once i checked also the Cylinder Capsule Collider component Is Trigger. so now in the rigidsbody both Use Gravity and Is $$anonymous$$inematic are checked ! And also the Collider Is Trigger is checked only on the Cylinder.

Now when the enemy collide with the Cylinder it's working it stop there using a break point.

avatar image moltow Chocolade · Aug 06, 2017 at 09:01 PM 0
Share

Is this the behavior you want? If you use the Cylinder's Capsule Collider as a Trigger, your enemies will be able to run right through the cylinder, right?

avatar image Chocolade moltow · Aug 06, 2017 at 09:41 PM 0
Share

Three things i forgot to mention.

First the cylinder i changed it's scale to be like a circle and this is only for setting a range where the enemy enter and leave. I have another gameobject that is a turret and stay in the center of the cylinder. This is all for a tower defence game.

it's only for testing so the enemies will have a waypoints route so they will never get too close to touch or pass through the cylinder/s.

Now i'm using my waypoints script so the enemy is getting close to the cylinder but then move back to the other side since i did that in distance of 30 before the cylinder change movement direction.

So i'm not sure if this is so important if i use the Capsule Collider trigger. What do you think ? If i'm doing it all for a tower defence game.

This is image showing the turret in the middle of the clyinder and the cube on the left is the enemy.

TD

So the event ontriggerenter will be to tell the turret when to start shooting on the enemy. And ontriggerexit when to stop shooting. This cylinder is just to set the shooting range.

What do you think i mean by logic ?

td002.jpg (77.0 kB)

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

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

How can i make an entrance and exit in this maze ? 1 Answer

How can I animate linerenderer lines over time ? 1 Answer

How can i find a thirdpersoncontroller hand and attach object to the hand ? 1 Answer

How can i check/wait until the gameobject will end the rotation ? 1 Answer

How can I call the Load method and/or the ShootingSettings method also only once in the Update ? 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