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 Acelondoner · Oct 30, 2012 at 06:50 PM · collisionrigidbodycapsule

Why will this collision check not fire?

I have 2 capsules. I control one and the other is AI controlled. I am trying to check if the player or AI capsules collide with each other. They are both rigid body's.

Here is the code which is attached to mt player capsule.

 using UnityEngine;
 using System.Collections;
 
 public class Particles : MonoBehaviour
 {
 
     // Use this for initialization
     void Start()
     {
 
     }
 
     void OnCollisionEnter(Collision collision)
     {
         if (collision.gameObject.tag == "Enemy" || collision.gameObject.tag == "Player" && collision.relativeVelocity.magnitude > 0.1)
         {
             Debug.Log("Collision detected");
         }
     }
 
     // Update is called once per frame
     void Update()
     {
 
     }
 }
 
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
1
Best Answer

Answer by ThePunisher · Oct 30, 2012 at 11:54 PM

Ok, here's the possible problems I can see.

  1. You didn't attach the script to either object.

  2. The check you have in that method is failing, meaning that neither of your objects have their tags set to whatever it is you are checking (ie Enemy, Player)

  3. One of your objects is missing a Collider component.

  4. You enabled the "isTrigger" property on your colliders. This calls OnTrigger methods instead (http://docs.unity3d.com/Documentation/ScriptReference/Collider-isTrigger.html).

Let us know which one of these was causing your problem.

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 ThePunisher · Oct 30, 2012 at 11:55 PM 0
Share

I would remove the check for the velocity until you can get the colliders to trigger.

avatar image
0

Answer by Montraydavis · Oct 31, 2012 at 06:31 AM

I bet it has to do with this line here. I see it happen very often, and I even do it sometimes.

 collision.gameObject.tag

needs to be

 collision.collider.tag

for one.

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

11 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

Related Questions

Sphere vs Capsule collider collision resolution 0 Answers

Damage with collision force? 0 Answers

What is an effective way of colliding but passing through another surface? 2 Answers

Player getting stuck in corners 0 Answers

Moving a player on a rigidbody platform that can collide 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