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 Galadhnen · Feb 04, 2013 at 07:20 PM · collisioncharacter controllerontriggerexitrigid bodyoncollisionexit

Does OnControllerCollider have an equivalent to OnCollisionExit?

Hello everyone!

This is my first time both posting on the forums and scripting in Unity, but I have enough experience of programming in Java to at least get by.

I'm trying to test a random tile spawn function that will be running in real-time (so it's not randomly pre-generated), and I'll explain it briefly:

The player starts in the center tile of a tight formation of nine tiles. When the player enters a new tile, the same formation needs to be created around that tile, however it shouldn't do so until the player leaves the center tile with a bit of a margin. Currently I have a trigger box covering the center tile and a bit of the adjacent tiles, so I know when the player is far enough away.

Now, the way I did this originally was with OnCollisionEnter, OnCollisionStay and OnCollisionExit, as I was testing it out with a rigid body cube that I had given a simple movement script. As I realized I may want a Character Controller instead, my method required me to use OnControllerColliderHit instead, and I was rather stumped at how to make that work.

So my first question is: are there any equivalent variants of OnControllerCollider that works like the three previous functions I was using?

Even better would be if I could have an OnTriggerExit (on my trigger volume over the center tile) that can call a function in my Character Controller to see what tile it is currently touching (and if the player is in the air, it'll keep checking until the player is actually touching a tile). But is there any such function I could call?

Anyway, despite this minor setback of mine, I must say I do like Unity a lot better than I did UDK.

Thanks a lot! // Rickard

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by hoy_smallfry · Feb 04, 2013 at 08:59 PM

It doesn't seem like there are any functions like what you are looking for: http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.html

Just to be clear, the each tile has a script, and all scripts are responsible for how other tiles are generated around them?

If that's the case, Here's what I propose: Make a parent object for all those tiles. The parent is responsible for creating the tiles, but waits for a message to create. Each tile has a sphere trigger collider, just to have collision thats equal distance from the center of all tiles - no matter what angle you come at, the radius of the sphere is the distance from the center you want the trigger to start. Plus, the sphere collision is the simplest for physics to compute. When there is a hit, the tile tells the parent to create tiles that aren't already around it. Additionally, you can make it so that the first time it hits is the only time the master gets the message, so there are no redundant calls.

That way, you have one master in charge of everything, and all he does is wait.

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 Adam-Buckner ♦♦ · Feb 04, 2013 at 11:07 PM 0
Share

Certainly, just to add to this, a CharacterController will activate a trigger.

If you create a scene with a basic 1st or 3rd person character controller, a plane, directional light and cube with the cube's collider set to isTrigger... and add the following script to the cube (assu$$anonymous$$g you have the cube and CC resting on the plane) when the CC penetrates the cube, it will generate all trigger event messages. The point is that you let the CC activate the triggers, you don't expect the CC to be the trigger.

 function OnTriggerEnter () {
     Debug.Log ("OnTriggerEnter");
 }
 
 function OnTriggerStay () {
     Debug.Log ("OnTriggerStay");
 }
 
 function OnTriggerExit () {
     Debug.Log ("OnTriggerExit");
 }

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

11 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

Related Questions

Box collider with rigid body yet enemies still pass through each other. 1 Answer

How do I script a script to put on a static game object, to detect when the character controller is colliding with it? 1 Answer

Creating custom character controller collision checking 0 Answers

Odd character controller behavior when a shield object parented to child 0 Answers

Ragdoll driven game 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