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 Dreamblur · Feb 27, 2011 at 11:04 PM · collisionrigidbodycharactercontrolleroncollisionentercollisiondetection

Does OnCollisionEnter only get called when the scripted object initiates the collision?

Does the OnCollisionEnter method only get called when the game object on which the script is attached to is the one which initiates the collision?

Listed below are the results of a few tests I've done that have led me to this query.

Object 1 (CC) = character controller with collider

Object 2 (RB) = non-kinematic rigidbody with collider

Case 1: CC is not moving and is below RB, RB is falling down due to gravity

Result: RB falls on top of CC, RB initiates the collision, OnCollisionEnter is called

Case 2: RB is not moving and is below CC, CC is falling due to gravity simulated by a character controller movement script

Result: CC falls on top of RB, CC initiates the collision, OnCollisionEnter is NOT called

Case 3: CC is not moving and is above RB, RB is falling up due to reversed gravity

Result: RB falls on the bottom of CC, RB initiates the collision, OnCollisionEnter is called

Case 4: RB is not moving and is above CC, CC is falling up to reversed gravity simulated by a character controller movement script

Result: CC falls on the bottom of RB, CC initiates the collision, OnCollisionEnter is NOT called

The OnControllerColliderHit method on my character controller always get called in all cases.

Several varieties of these 4 cases have also been tried, but the results were always the same.

So, like I was asking, does the OnCollisionEnter method only get called when the game object on which the script is attached to is the one which initiates the collision, or is my program just wonky?

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

4 Replies

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

Answer by Dreamblur · Jul 07, 2011 at 07:15 PM

While answering a forum post, I realized what the actual issue was. A static rigidbody would technically be sleeping, and since collision events with character controllers aren't detected by a sleeping rigidbody, no collision message would be sent.

This is an old post. I just wanted to post the "answer" in case someone else was wondering about this. No further answers are necessary.

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 yoyo · Jul 10, 2013 at 11:17 PM 0
Share

I just ran into the same issue, and I'm not using a character controller. Turns out a sleeping rigidbody won't generate OnCollisionEnter messages for any collider. $$anonymous$$y.

avatar image
3

Answer by owenpat · Feb 28, 2011 at 01:56 AM

I think the problem is that CharacterControllers are a little odd. Some people here advocate for using a standard collider+RB for your character, with a redone script, if you want them to act more like "physics objects."

I recently performed a similar test where I dropped a rigidBody collider onto a (non-RB) collider, and everything worked fine -- both OnCollisionEnters got called every time, for every bounce.

I believe what happens when a CharacterCollider hits something is the same reason charControllers can't push things. Some magic jumps in and deals with the situation, stopping the character short, before it officially hits and calls the other collider.

Other things I've noticed: triggerBoxes don't work when they are moved (use SphereCasts,) and CollisionStay isn't called for objects rolling on the ground (but that was 2 versions ago.)

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 Dreamblur · Feb 28, 2011 at 05:47 AM 0
Share

Yes, I think the character controller component is the one causing the problem as well. The rigidbody calls the OnCollisionEnter method when it's the one colliding with a non-moving character controller, but nothing happens when said rigidbody is the one not moving.

avatar image
0

Answer by AngryOldMan · Feb 27, 2011 at 11:33 PM

I'm not sure what you mean by initiates the collision. What object has the OnCollisionEnter script attached to it and what are you actually trying to do? It may just be me but what your trying to explain isn't clear at all. To answer your question OnCollisionEnter is called when this collider/rigidbody has begun touching another rigidbody/collider. check out http://unity3d.com/support/documentation/ScriptReference/Collider.OnCollisionEnter.html for a bit more info on the process.

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 Dreamblur · Feb 28, 2011 at 05:43 AM 0
Share

What I basically want is some way for the "character" (a game object with a character controller and a collider) to activate OnCollisionEnter from a script attached to a non-moving game object with a non-kinematic rigidbody and a collider. When I say "initiate the collision," what I mean is that the object is moving and colliding into a non-moving object. In all the testing that I've done, OnCollisionEnter on the non-kinematic rigidbody doesn't get called when the non-kinematic rigidbody is not moving and the character controller is.

avatar image
0

Answer by AngryOldMan · Feb 28, 2011 at 02:04 PM

Ah thank you for clarifying. you can either try what owenpat has suggested, i think it's quite common, however if your want to keep your character controller on (we've used CC from the beginning and never had a problem,plus i believe it's easier to move and customise than a rigidbody) still not sure why you want this to happen, you know a rigidbody is usually for moving a simulating physics, if it always stays still then you can just have a collider on it to act as a trigger zone. If possible a little more info about what exactly you want to achieve in game (like "i want my character, on entering the trigger, to jump") Then we may be able to help even more. on your playable character make sure it has a character controller, i don't think it needs the collider. Make sure it's tagged "Player" on your non moving game object (the one with a rigidbody) make sure it does have a collider and it is ticked to be a trigger. On the rigidbody object put a script that says something like: this states that when the player enters the trigger area (initiates collision) the object will access the players script and change a variable.

var playerPrefab : Gameobject;
function OnTriggerEnter (collision : Collider)
{
    if (collision.gameObject.CompareTag  ("Player")) 
    {
        JumpPlayer = playerPrefab1.GetComponent(PlayerMoveScript);
        JumpPlayer.JUMPON = JumpPlayer1.JUMPON = true;
    }
}

Then on the PlayerMoveScript something along the lines of:

static var JUMPON : boolean = false; var jumpAccel : int; var jumpHeight : int;

if (JUMPON == true) { moveDirection = transform.TransformDirection(moveDirection*jumpAccel); moveDirection.y = jumpHeight; JUMPON = false; }

Sorry for the forum code, we have an object with a trigger on it which our player enters to jump (its basically a jump pad) obviously change some of the variable so that it fits your game and what you need to do. im just making an exapmle based on what you've told me if im missing a trick here, tell me and i will edit this post accordingly!

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

CharacterController and Normal rigidbody Box Collider Collision issues 0 Answers

Two Character Controllers Colliding... 0 Answers

Collision Only being detected on one of the objects involved in the collision - C# 0 Answers

Character Controller goes through objects 2 Answers

Using rigidbody for collisions only, not movements? 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