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 SBull · Jun 28, 2013 at 08:51 PM · javascriptcharactercontrollerclimb

Is there an equivalent to OnCollisionExit for OnControllerColliderHit?

I am trying to make a 2D characterController climb an object. I can get them to start moving up when they come into contact with that object using:

function OnControllerColliderHit(hit : ControllerColliderHit)

{

 if(hit.transform.tag == "treeTrunk")
 {
 ClimbingTree();
 }

}

but unfortunately I can't figure out how to tell it to stop when it reaches the top and is no longer touching the object anymore. Any suggestions?

Comment
Add comment · Show 3
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 Immanuel-Scholz · Jun 28, 2013 at 09:30 PM 0
Share

I don't really understand the problem. I was under the impression that OnControllerColliderHit is called only when you call controller.$$anonymous$$ove()?

So you want a function called, when controller.$$anonymous$$ove() does not call OnControllerColliderHit?

You could just set a bool member variable to false before calling controller.$$anonymous$$ove, then set it to true in OnControllerColliderHit and if its still false after the $$anonymous$$ove, then no collider hit was called.

But this seems rather ... .. "indirect" to me :). So I guess I just didn't understood your problem. :(

avatar image SBull · Jun 29, 2013 at 08:28 PM 0
Share

Sorry, maybe I'm trying to use the OnControllerColliderHit function wrong. I'll just explain my problem and maybe there is another function that will work better for my situation.

I have a characterController that walks automatically along a 2D plane. I want it to begin climbing (moving up) automatically when it collides with an object. But once the characterController reaches the top of the object, it should stop moving up and begin walking across the top of the object. How can I tell my characterController that it is not touching the side of the object anymore so that it stops moving up? Hopefully that makes sense.

avatar image jstation · Jan 09, 2014 at 10:05 PM 0
Share

Should've tried this before, but I added a rigidbody2D to my ground and now I get onexit calls. This is still not an ideal solution. $$anonymous$$y ground is actually planets that float around and the player can jump between them. Adding a rigidbody2D allows them to move. I suppose I can just raise their mass or force them not to move with a script, but I would prefer not to. I've also checked $$anonymous$$inematic, which is fine for now but later I might want to have them orbit and move with forces.

Any info on the original question would still be helpful.

1 Reply

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

Answer by Immanuel-Scholz · Jun 29, 2013 at 09:06 PM

If your "climbing" surface is the same for all obstacles and the only one colliding with the obsticles is your player, then I recommend you use OnTriggerEnter and OnTriggerExit to detect when the player hits an obstacle.

If you need more information about the collision (e.g. to tweak your animation), you can use OnCollisionEnter/OnCollisionExit instead which gives you some information about the contact point and normal.

Comment
Add comment · Show 3 · 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 SBull · Jun 29, 2013 at 11:16 PM 0
Share

Thanks for your response. I'm still having an issue though. I changed it to:

function OnCollisionEnter (theCollision : Collision)

{

 if(theCollision.gameObject.tag == "treeTrunk")

 {

     isClimbing = true;
     Debug.Log("Touching the tree");
 }

}

But this does not seem to work. It won't even print the text for me. Is there something wrong in my code here?

avatar image Immanuel-Scholz · Jun 29, 2013 at 11:29 PM 0
Share

Hm.. do both objects have a rigid body? And at least one of them is non-kinematic? (reference documentation)

avatar image SBull · Jun 29, 2013 at 11:33 PM 0
Share

No. One is a characterController and the other is just a cube with a box collider. So OnCollsionEnter only works with two rigidbodies?

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

17 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

Related Questions

Struggling with jumping! 3 Answers

2d Ladder with character controller 2 Answers

Collision Detection 0 Answers

Increasing Camera "Bobbing" speed when character is sprinting 1 Answer

Character Controller moves forever after colliding with object 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