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 moynzy · Nov 27, 2014 at 08:19 AM · collisioncollidersmelee

Unity Collision Does not work unless player is moving

example1

So from the example1 you can see that the two colliders are overlapping.But no debugs are coming through. The collider is attatched to a child object of the goblin. Then this script is added to this child(sword).

 using UnityEngine;
 using System.Collections;
 
 public class GoblinSword : MonoBehaviour {
 
 
     bool hit = false;
     void Update(){
         if(hit){
             Debug.Log("Ouch");
         }
     }
 
     void OnTriggerEnter(Collider other)
     {
         Debug.Log("triggered sword colidr");
         if(other.gameObject.tag=="Player"){
             Debug.LogWarning("hit player");
             hit = true;
         }
 
         if(other.CompareTag("Player")){
             Debug.LogWarning("hit player");
 
         }
     }
     void OnTriggerExit(Collider other)
     {
         Debug.Log("exited sword colidr");
         if(other.gameObject.tag=="Player"){
             Debug.LogWarning(" didnt hit player");
             hit = false;
         }
         
     
     }
 
 }

The only way I get some collision is when the player moves whilst the goblin is attacking, if I'm lucky and patient whilst moving, It works.

BUT if the player stands still and enemy is attacking, then nothing happens. Which defeats the object of having collision.

example2

Example two just shows how the sword is a nested object.

Comment
Add comment · Show 4
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 meat5000 ♦ · Nov 27, 2014 at 03:42 AM 0
Share

Does one of the objects have a rigidbody? How are you moving the objects involved in the collision? Colliders marked as trigger? (The ones you hope to use OnTrigger routine with)

Fix your errors then strap a kinematic rigidbody to your sword.

avatar image moynzy · Nov 27, 2014 at 06:22 PM 0
Share

@meat5000 I'm using a character controller. No one has a rigid body. How will this work?

avatar image tanoshimi · Nov 27, 2014 at 06:33 PM 0
Share

It won't... "Note that trigger events are only sent if one of the colliders also has a rigidbody attached."

http://docs.unity3d.com/ScriptReference/$$anonymous$$onoBehaviour.OnTriggerEnter.html

avatar image moynzy · Nov 27, 2014 at 07:08 PM 0
Share

Thanks for the comment guys, I'm currently trying to implement a resolve.

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by ipankaj93 · Jan 26, 2020 at 10:40 PM

@moynzy I came across the same problem and found a fix that worked. Setup - Player has a BoxCollider2d and a Kinematic RigidBody2d. Coliider is enabled only when space is hit.

             if (Input.GetKey(KeyCode.Space))
             {
                 attackCollider.enabled = true;
             }
             else
             {
                 attackCollider.enabled = false;
             }
 

But the collider was not detecting any collision until the player gameobject is moved.

I don't know the root cause, but it looks like that unity puts the RigidBody to sleep if there is no movement. Solution for this is to change the Sleeping Mode on the RigidBody component to Never Sleep. alt text

Hope this helps :)


capture.png (14.9 kB)
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 Christor_8 · Aug 03, 2020 at 01:02 PM 1
Share

Thanks, You saved me xD (5+ years past)! The case was in the Rigidbody Sleeping $$anonymous$$ode.

avatar image
0

Answer by richyrich · Nov 27, 2014 at 06:53 PM

Couple of things to consider:

1) You need additional code in the form of 'OnTriggerStay(Collider other)'. This will then tell you when colliders are continuing to collide, rather than just starting/exiting

2) Even with OnTriggerStay, you won't always get updated about the collision because the engine does not update continuously. You can change this to your preference. See link below for more information

http://docs.unity3d.com/ScriptReference/Rigidbody-collisionDetectionMode.html

Edit: Just thought of something... If you want collision detecting to be triggered, you need to move one of the game objects. So if they are stationary, but you still want collision checking, just move another object (without renderer) into the collision area.

Comment
Add comment · 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
0

Answer by amitDklein · Sep 14, 2020 at 05:12 PM

I think This will answer you

Comment
Add comment · 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

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

2D collision won't work? 2 Answers

Unity detecting collision without touching 1 Answer

How do you change the collisions of all of one sort of tile on a tilemap. Also, how do you change the collision box on tiles in your tilemap 0 Answers

Temporarily ignore collisions between player and enemies 2 Answers

Coin collecting with prefabs 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