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 Avery · Nov 03, 2010 at 01:37 AM · bugoncollisionenter

Bug With Collision Detection In Unity 3?

Sorry if this seems to be a newbie question. However i seems to have problems detecting collision between my player and the gameObject i want to detect. Am i writing it wrong somehow?

function OnCollisionEnter(collision : Collision) { Debug.Log(" i got u");

 if(collision.gameObject.Find("CarrotType1(Clone)") && getNos == 1)
 {
     Debug.Log("hello");
     //Destroy(targets);
 }

 if(collision.gameObject.Find("CarrotType2(Clone)") && getNos == 2)
 {
     Debug.Log("hello");
     //Destroy(targetz);
 }

}

it does not even output the "I got you" message in the Debug. Thanks in advance for any suggestions that i might be doing it wrong. :)

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 gabrielloke · May 12, 2012 at 01:50 AM -1
Share

I have been facing the same problem...if I drag an prefab into the scene it works, but when I respawn point, the instantiated object stops working as well.

avatar image Bunny83 · May 12, 2012 at 01:53 AM 0
Share

@gabrielloke: this is not an answer to the question. I've converted your "answer" into a comment. If you want to ask your own question, post it as question an not as answer.

4 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by AudiOishi · Dec 10, 2010 at 10:27 PM

One thing to note: When using onTriggerEnter (this may also apply to collisions) the documentation says that both objects need either a collider or a rigidbody.

In my experience, this is not correct.

This is only true if BOTH Objects are moving.

If one of the objects is standing perfectly 100% still, then the other object will need to have a rigidbody as well.

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
-1

Answer by Avery · Nov 03, 2010 at 02:31 AM

Thanks again for the suggestion. However i tried both ways. and it doesnt work also. ); This the whole code for this class. maybe its more informative. =/

class Collisions extends StageWaypoint {

public var targets : GameObject; public var targetz : GameObject;

private var thisNum : int; private var getNos : int;

function Awake() { }

function Start() {
//Debug.Log(targets); //Debug.Log(targetz); //Debug.Log("hellosssss"); }

function Update() { targets = GameObject.Find("CarrotType1(Clone)"); targetz = GameObject.Find("CarrotType2(Clone)"); getNos = thisNum;

 //Debug.Log(getNos + " this is rec");
 //Debug.Log(targets);

}

function OnControllerColliderHit(collision : ControllerColliderHit) { Debug.Log(" i got u");

 if(collision.collider.name == "CarrotType2(Clone)" && getNos == 1)
 {
     Debug.Log("hello");
     Destroy(targets);
 }

 if(collision.collider.name == "CarrotType2(Clone)" && getNos == 2)
 {
     Debug.Log("hello");
     Destroy(targetz);
 }

}

function recNum(no : int) { thisNum = no; }

}

Comment
Add comment · Show 8 · 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 Atnas1010 · Nov 03, 2010 at 02:36 AM 0
Share

Sorry for asking dumb questions, but is the script running on the object with the charactercontroller, and do you still not get "i got u" printed?

avatar image Avery · Nov 03, 2010 at 02:41 AM 0
Share

Yeps this script is attached to the object with the charactercontroller. and yeps again. i still dont get the "i got u" printed.

avatar image Atnas1010 · Nov 03, 2010 at 02:43 AM 0
Share

Well, I'm out of ideas to try out, sorry :(

avatar image zannghast · Nov 03, 2010 at 03:05 AM 0
Share

I've got a dumb question myself. xD What class(es) does StageWayPoint inherit from?

avatar image Avery · Nov 03, 2010 at 03:10 AM 0
Share

lols it inherit from the base class $$anonymous$$onoBehaviour =/

well.. i redid the whole project. and it works.... once. after that it stop detecting collision anymore.

Show more comments
avatar image
0

Answer by Atnas1010 · Nov 03, 2010 at 02:00 AM

Have you attached a rigidbody to either the player or the carrots? And a collider to both of them?

Also, your if statement doesn't make that much sense. I would use something like

collision.collider.name == "CarrotType2(Clone)"

Does this solve the problem?

Comment
Add comment · Show 5 · 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 Avery · Nov 03, 2010 at 02:13 AM 0
Share

Thanks for the suggestion, however when i tried ur method. it returns an error that says,

Assets/Script/Collisions.js(40,30): BCE0019: 'name' is not a member of 'UnityEngine.Collision'.

Yeps, i have a character controller attached to my player, as well as a rigid body and a box collider attached to the carrots.

I don't know if this makes any sense. =/

Yesterday before i off the program. Everything was working fine. When i reopen the program the next time, usually all my collision detection failed.

avatar image Avery · Nov 03, 2010 at 02:22 AM 0
Share

Apparently, the OnCollisionEnter funciton itself is not even running when the game started.

 function OnCollisionEnter(collision : Collision)
 {
     Debug.Log(" i got u");
     }
avatar image Atnas1010 · Nov 03, 2010 at 02:24 AM 0
Share

I edited my script (mistake on my part, sorry) If the event still doesn't get called, you could try changing it to an OnControllerColliderHit(collision : ControllerColliderHit)

avatar image zannghast · Nov 03, 2010 at 02:33 AM 0
Share

did you double check if the isTrigger flag on the box collider is turned off?

avatar image Avery · Nov 03, 2010 at 02:33 AM 0
Share

thanks, however either ways it doesnt seems to work. =/ i couldnt fathom out any problem with it at all. );

avatar image
0

Answer by Proclyon · Nov 03, 2010 at 03:17 PM

Try using THIS Unity3D collision method. It should make life a bit easier:

It's a simple check for looking if the collision box of your moving charactercontroller has come into contact with something above below etc. Little else is needed for simple collision detection

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

1 Person is following this question.

avatar image

Related Questions

OnCollisionEnter2D not being called on entering new tile once already called. 1 Answer

Latest 5.2.2p3 Patch Breaks 2D Collision? 13 Answers

Delayed Collisions Bug (includes video demonstration) 1 Answer

iOS simple shader does not work 1 Answer

Something went wrong in the Beast lightmapper: Duplicate name 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