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
1
Question by Koder · Apr 03, 2011 at 12:38 AM · collisiondetect

gameObject not detecting collision

Okay, so I got my player controller colliding with an object that I want to pick up, and it does collide with it, but in the pick up item's script it is set to delete itself upon collision and does not, and with a Debug.Log I found out that even though the player is colliding with it physically, it isn't... not sure how to say it but it doesn't output anything when I type Debug.Log(collider.gameObject.tag); when the player is tagged as Player. And I know the debug.log works because the bullets I shoot at it output an "Untagged" in the console.

I'll reference some code:

function Start()
{
    //Physics.IgnoreLayerCollision(10, 11, true);
    //Physics.IgnoreLayerCollision(9, 11, true);  //commented out for debugging
    //Physics.IgnoreLayerCollision(11, 11, true);
}
function OnCollisionEnter(collision : Collision)
  {
    Debug.Log(collision.gameObject.tag); //<--- this outputs nothing when the player hits it
    if (collision.gameObject.tag != "Player") 
      return;
    Inventory.AddItem(item);
    Destroy(gameObject);
  }

I also tried making it collide with other random objects and they also don't seem to pass a .tag value, so it seems the only thing that can collide with this object is a bullet.

Edit for statement:

function OnControllerColliderHit (hit : ControllerColliderHit) 
 {
  var body : Rigidbody = hit.collider.attachedRigidbody;
  Debug.Log( hit );
  Debug.Log( body );   
 }

Both debugged nothing to the log.

Comment
Add comment · Show 1
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 Statement · Apr 03, 2011 at 10:17 AM 0
Share

You sure your scripts are on the same object that has your character controller and collider (and not a child/parent of it)? If you are unsure, you can try this easily by doing function Start() { print(" I have " + GetComponent(CharacterController) ); }

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Melang · Aug 21, 2014 at 06:23 AM

  1. Make sure at least one of the colliding objects has a Rigidbody attached.

  2. If your colliders and rigidbodies are 2d, the function should be called

function OnCollisionEnter2D(coll: Collision2D)

If it still doesn't work, add a

Debug.Log("on collision enter");

to see if it even triggers.

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 Statement · Apr 03, 2011 at 12:45 AM

Sorry for short reply - going bed - but check out OnControllerColliderHit instead of OnCollisionEnter.

Comment
Add comment · Show 2 · 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 Statement · Apr 03, 2011 at 12:46 AM 0
Share

Alternatively (unsure if it helps) you could try adding a rigidbody to the collider and set is$$anonymous$$inematic to true.

avatar image Koder · Apr 03, 2011 at 12:53 AM 0
Share

Alright, checking both of those. I added to my main post the code I added with oncontrollercolliderhit which didn't seem to work, although I'm still trying new things with it now.

avatar image
0

Answer by zak666 · Aug 21, 2014 at 04:36 AM

Still dose nothing and yet no script errors sure was a good try

 #pragma strict
 
 
       function OnTriggerEnter (other:Collider){
     if(other.gameObject.name == "PlayerHyperShot1"){
     Debug.Log("It went through");
       ProbeEvent.ProbeScore += -1;
     _MASTER.Score += 200;
     Destroy(gameObject.Find("PlayerHyperShot1"));
   
     
     }
     }
  
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

2 People are following this question.

avatar image avatar image

Related Questions

How to add the right amount of points when my player destroys a gameobject? 0 Answers

Collision flag entering a tagged object's collider 2 Answers

Detect Color in "If" Statement 2 Answers

Detect 2 colliders by trigger 1 Answer

Collision with ground problem (no collision detected) 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