• 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 DesireProwz · Oct 05, 2015 at 07:50 PM · collisioncollision detectiondetect

Object does not check for collision again after first time

I have to create a protoype game for school about economics, but I'm kind a stuck. It is a simple game where soldiers fight against eachother. Each soldier has his own health and damage. Every soldier has a box collider and a rigidbody attached. I'm checking the collision as followed:

 void OnTriggerEnter (Collider other) {
     if (other.gameObject.tag == "EnemyMelee") {     
         anycollision = true;           
         meleeInSight = true;
         enemyMeleeController = other.GetComponent<EnemyMeleeController> ();
 }

In the OnTriggerExit I simply set the two booleans to false. I have a timer that counts down towards zero and when it reaches zero the soldier simply attacks the enemy and the enemyhealth is counting down to 0 with each hit. When it reaches zero the object is first translated to another position outside the gameworld and then destroyed. Im changing the position so the OnTriggerExit detects it.

When the booleans are set to true the player speed is set to 0 to stop movement and start attacking and when it is set to false the player gains his original speed back, however after one or more collisions the player speed stays solid at its original one and the player never stops.

 void OnTriggerExit (Collider other) {
     anycollision = false;
     meleeInSight = false;
     speed = 5;
 }

In the Update method I'm setting the speed to 0.

 void Update() {
     if (anycollision) {
         speed = 0;
     }
 }
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 _Yash_ · Oct 06, 2015 at 10:08 AM 1
Share

It may possible that player is colliding with multiple enemies, if thats the case, it may be possible that because of one enemy OnTriggerExit is called and bool will become false but player is still colliding with others. So try having a int counter which increases when trigger enter and decrease on TriggerExit and check if counter is zero nothing is colliding.

avatar image DesireProwz _Yash_ · Oct 06, 2015 at 11:00 AM 0
Share

Thanks Yash I think that fixed the problem!

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

32 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

Related Questions

Rotate camera on collision of character 1 Answer

Problem with DontGoThroughThings script 0 Answers

Help With NavMesh 0 Answers

C# - My increament code is not working? 1 Answer

Player passenger moving when being pushed by two platforms 0 Answers

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