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 Jamoy1993 · Jan 17, 2014 at 02:15 AM · rigidbodytagsrigidbody-collisioncollision.contacts

I want to get a projectile to return the surface tag but it returns untagged.

Basically i want my projectile to mark the map if its tagged as LevelParts but the problem is that the projectile isnt even detecting the tags on the level. A raycast version works perfectly but this one does not.

The code is obviously detecting collisions but not correctly. What have i done wrong?

     function OnCollisionEnter(collision : Collision) 
     { 
         for(var contact : ContactPoint in collision.contacts)
         {
          Debug.Log("This colliders tag is named: " + collision.contacts[0].thisCollider.transform.tag);
         }
     }

I have tried even changing "ollision.contacts[0].thisCollider.transform.tag" to "contact.thisCollider.tag" and other things.

If its any more help this is the actual piece of code i am actualy wanting this to work on.

     function OnCollisionEnter (collision : Collision)
     {
         for (var contact : ContactPoint in collision.contacts)
         {
             if(decalHitWall && contact.thisCollider.tag == "LevelParts")
             {
                 Instantiate(decalHitWall, contact.point + (contact.normal * floatInFrontOfWall), Quaternion.LookRotation(contact.normal));
                 Destroy(gameObject);
             }        
         }
     }
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 robertbu · Jan 17, 2014 at 02:27 AM 0
Share

I'm a bit confused about what you are trying to do here. Your first code makes no sense to me since you loop through all the contact points, but you always only print out the data for the first contact.

The second body is also a bit confusing since you use 'thisCollider' rather that 'otherCollider'. If this script is on the projectile and if it is trying to mark what it hit, then I think you want 'otherCollider.tag' for your test.

avatar image Jamoy1993 · Jan 17, 2014 at 10:59 PM 0
Share

Put it simply i want the code to:

Detect collision with any object that has the tag "levelParts"

Place a decal on the contact.point and rotate it to the contact.normal.

Destroy the bullet.

The bullet is basically a sphere with a box collider attached.

3 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by KellyThomas · Jan 17, 2014 at 11:28 PM

Try:

 function OnCollisionEnter(collision : Collision) 
 { 
    for(var contact : ContactPoint in collision.contacts)
    {
        Debug.Log("The other collider's tag is named: " + contact.otherCollider.tag);
    }
 }
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 Jamoy1993 · Jan 18, 2014 at 12:58 AM

     function OnCollisionEnter (collision : Collision)
     {
         for (var contact : ContactPoint in collision.contacts)
         {
             if (decalHitWall && contact.otherCollider.tag == "LevelParts")
             {
                 Debug.Log("Tag = " + contact.otherCollider.tag);
             }
         }
     }

This was what i was looking for.

THANKS ROBERT your input heped me by mentioning otherCollider.

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 fuzzysmurf · Jan 18, 2014 at 12:00 AM

If their is only one GameObject interacting w/ these contact points, you can add them all to a seperate layer, and use Physics.OverlapSphere to detect them all first. then you can check for the tag afterwards. guaranteed it will work.

 Collider[] parts;
     
 parts = Physics.OverlapSphere(this.transform.position, 4); //you can change the parameters if you're using layers.
     
 foreach (Collider part in parts)
 {
 if(part.gameObject.tag == "levelParts")
 {
 //do stuff
 }
 }

of course if you do this, you will have to activate it upon collission, or on trigger.

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

20 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

Related Questions

Problem with Rigidbody control script! (collision with perpendicular walls problem) 1 Answer

Rigidbody (2D) stays in fixed angle even when colliding 1 Answer

Offsetting player position from a moving Rigidbody. 0 Answers

OnCollisionEnter and rigidbody problem 1 Answer

Rigidbody slightly intrudes another one while pushing it 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