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 Addyarb · Apr 20, 2014 at 08:06 AM · collisionrigidbodystatic

Can't figure out my collision mistake, please help!

alt textHi Unity,

I've been working on this issue for about 3 days to no avail.

Issue:

I am trying to get a projectile's capsule collider (with a rigidbody attached, no isTrigger) to collide with a player's capsule collider (capsule collider with isTrigger).

I checked the collision matrix, but nothing seems to be happening? I'll attach the relevant code below to see if it's perhaps something wrong with the way it's written.

Thanks for the help!

C#

 if(hit.transform.tag == "BlueTeamTrigger" ||
                hit.transform.tag == "RedTeamTrigger")
             {
                 
                 expended = true;
                 
                 //Instantiate an explosion effect.
                 
                 Instantiate(blasterExplosion, hit.point, Quaternion.identity);

The colliders attached to the players are children of the players, and are marked with RedTeamTrigger or BlueTeamTrigger Respective to what team they're on.

blasterpic2.jpg (253.1 kB)
blasterpic.jpg (248.2 kB)
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 Benproductions1 · Apr 20, 2014 at 01:29 PM 0
Share

What the hell is the "collision matrix"? Have you tried debugging the problem?

avatar image Addyarb · Apr 20, 2014 at 02:47 PM 0
Share

Here's a link to the collision action matrix in case you were wondering. http://answers.unity3d.com/questions/148923/collisions-do-they-need-two-rigidbodies.html

avatar image Benproductions1 · Apr 21, 2014 at 02:03 AM 0
Share

Right, it's a documentation thing. Not an actual part of the API. Have you tried debugging the problem?

avatar image Addyarb · Apr 21, 2014 at 02:58 AM 0
Share

Well I'm not exactly sure what you mean by debugging, but I put debug.log("hit the collider"); etc. after each function, and the only way I could get anything to appear was when I set the rigid body to kinematic. However this also renders my player uncontrollable, as he/it is controlled by applied force.

Thanks for the responses!

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Burla · Apr 20, 2014 at 01:50 PM

I suggest you read this post.

http://answers.unity3d.com/questions/454479/toggling-is-trigger-on-box-collider-causes-it-to-n.html

"Hello. Is Trigger in unity disables the function of the collider and turns it into a passable trigger."

Let me know if this helped you.

Comment
Add comment · Show 7 · 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 Addyarb · Apr 20, 2014 at 05:42 PM 0
Share

I'm afraid this didn't do it for me. I've tried loads of combinations according to the collision action matrix and none of them seem to be working for me. It feels like I'm missing something obvious, as the projectile seems to just pass through the player no matter what I set them to. I've tried both rigidbodies, both triggers, both non-trigger (static) and no luck.

avatar image Burla · Apr 20, 2014 at 06:41 PM 0
Share

In the code you provided you don't call the OnCollisionEnter() function. I suppose you have it somewhere in your code? Just making sure.

avatar image Addyarb · Apr 21, 2014 at 02:12 AM 0
Share

I didn't think I needed a OnCollisionEnter function if I was using hit.transform.tag? Here's the full script ($$anonymous$$us the variable declarations) for reference, it's actually part of a tutorial series that I've followed to a T, but the collider issue seems to persist:

 using UnityEngine;
 using System.Collections;
 
   
     // Use this for initialization
     void Start () 
     {
         myTransform = transform;
         
         //As soon as the projectile is created start a countdown
         //to destroy it.
         
         StartCoroutine(Destroy$$anonymous$$yselfAfterSomeTime());
     }
     
     // Update is called once per frame
     void Update () 
     {
         //Translate the projectile in the up direction (the pointed
         //end of the projectile).
         
         myTransform.Translate(Vector3.up * projectileSpeed * Time.deltaTime);
         
         
         //If the ray hits something then execute this code.
         
         if(Physics.Raycast(myTransform.position,myTransform.up, out hit, range) &&
            expended == false)
         {
             //If the collider has the tag of Floor then..
             
             if(hit.transform.tag == "Floor")
             {
                 expended = true;
                 
                 
                 //Instantiate an explosion effect.
                 
                 Instantiate(blasterExplosion, hit.point, Quaternion.identity);
                 
                 
                 //$$anonymous$$ake the projectile become invisible.
                 
                 myTransform.renderer.enabled = false;
                 
                 
 
             }
             
             
             
             if(hit.transform.tag == "BlueTeamTrigger" ||
                hit.transform.tag == "RedTeamTrigger")
             {
                 
                 expended = true;
                 
                 //Instantiate an explosion effect.
                 
                 Instantiate(blasterExplosion, hit.point, Quaternion.identity);
                 
                 
                 //$$anonymous$$ake the projectile become invisible.
                 
                 myTransform.renderer.enabled = false;
                 
                 
 
                 
                 
                 //Access the HealthAndDamage script of the enemy player
                 //and inform them that they have been attacked and by whom.
                 
                 if(hit.transform.tag == "BlueTeamTrigger" && $$anonymous$$m == "red")
                 {
                     HealthAndDamage HDscript = hit.transform.GetComponent<HealthAndDamage>();
                     
                     HDscript.iWasJustAttacked = true;
                     
                     HDscript.myAttacker = myOriginator;
                     
                     HDscript.hitByBlaster = true;
                 }
                 
                 if(hit.transform.tag == "RedTeamTrigger" && $$anonymous$$m == "blue")
                 {
                     HealthAndDamage HDscript = hit.transform.GetComponent<HealthAndDamage>();
                     
                     HDscript.iWasJustAttacked = true;
                     
                     HDscript.myAttacker = myOriginator;
                     
                     HDscript.hitByBlaster = true;
                 }
             }
             
         }
     }
     
     
     IEnumerator Destroy$$anonymous$$yselfAfterSomeTime()
     {
         //Wait for the timer to count up to the expireTime
         //and then destroy the projectile.
         
         yield return new WaitForSeconds(expireTime);
         
         Destroy(myTransform.gameObject);
     }
 }
 
 
 
 
 
 
 
 
 
avatar image Burla · Apr 21, 2014 at 09:26 AM 0
Share

Does it explode and get invisible if you hit the ground?

avatar image Addyarb · Apr 21, 2014 at 09:35 AM 0
Share

It does, yes.

Show more comments

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

22 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

Related Questions

Having a kinematic rigidbody detect collision with a collider without a rigidbody 7 Answers

Why does my player fly through my barrier? 2 Answers

Colliding fast moving object with a slow moving object 1 Answer

Any way to ignore collision between rigidbodies and colliders/character controllers? 1 Answer

Fixed Joint - Collision Problem 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