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
0
Question by Mushu · Aug 06, 2013 at 01:41 PM · raycastcollidercharactercontrollercube

Magical Rigidbody/CharacterController free character...controller - Unity

Hi

So it seems a lot of people have spoken against the evils of using a rigidbody in Unity so I have been using a CharacterController which is about 99% of what I need. This was fine until I was asked to look into that 1% and see if anyone wouldn't mind sharing how they handle character's and collisions.

The player character we're using is a squarish shape so using the CharacterController's Capsule collider is a bit of a nuisance. I did try use a Box Collider but that resulted in 3 problems: 1 - Using RayCast means I would need to emit a ray from each corner when moving he character which means at least 4 rays but at most 12 per frame. Even so if an object could still pass through the centre of the character undetected. 2 - The OnCollision events only get triggered if a rigid body is attached to the object (which kinda defeats the purpose of all this effort) 3 - Physics.CheckSphere is not Physics.CheckCube... and Physics.CheckCube doesn't exist (nor does Physics.CheckSphere return a list of the colliders within the sphere for additional checking with collider.bounds.Intersects).

If you can please let me know what you use for your player's collisions (or if you do just use character controller too just say so too).

P.S I have attached a drawing of our punk rock horse character code named bob in the collision cube I'd like to use. (It's actually meant to be a zebra but now you see why the powers that be have me doing the programming)

alt text

untitled-1.png (24.7 kB)
Comment
Add comment · Show 5
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 Aria-Lliane · Aug 06, 2013 at 02:03 PM 0
Share

$$anonymous$$aybe im saying something stupid, if so, im sorry. But when you say you want a cubed colision box on your character i imediatly think of adding a GameObject Box as a zebra's children(with a 'none' mesh), that would outomaticly add a box colider on it, I just dont know if the already existing "character controller" of the character would bypass the colisions of the box.

avatar image TSRajesh · Aug 06, 2013 at 03:01 PM 0
Share

Let me say what i tried and what i settled on.. $$anonymous$$y situation is similar.. I use a secondary character (Horse, parented to the character controller). Adding rigidbody (kinematic trigger) on the secondary character was not very effective, and So, I tried raycasting from the 4 corners, (and teh centre point in teh direction i am moving) but still something could pass in between.. Then i went for checksphere & bound intersects, which worked O$$anonymous$$. (If you say checksphere doesn't return anything, then you have some issue.. 'coz it works for me) But bound works in Axis-Aligned.. So, unless you are aligned to teh world axis, or your character is a perfect cube, it would give a lot of space around it.

So at last, i settled for a ghost object.. A primitive cube resized to match the (extended) character size, with renderer turned off.. and move/rotate that ghost object and check for intersects. I make sure i recalculate the 8 corner vertices of teh ghost object as non axis-aligned, so that i can get pretty close without intersecting.

One more trick that helped me to detect intrusion is.. Ins$$anonymous$$d of raycasting outwards, i raycast towards teh other corner of the bounding box, (in both directions.. as teh raycast won't work if it is already inside a collider) , so that i can detect anything that intersects me.. I'm pretty much settled with my solution now.

avatar image TSRajesh · Aug 06, 2013 at 03:04 PM 0
Share

@Aria, The problem is, if we just have a collider on our character, it will not detect any collisions with other colliders. We must have a rigidbody or a character controller..

avatar image Aria-Lliane · Aug 06, 2013 at 05:05 PM 0
Share

Yes, i tried something on my own, i added a rigidbody to the box(children of the character) and the controler kept coliding with the box making the box just float around the character lol, where we want them to be the same thing or one over the other, maybe you could make a layer for the box and make the controler collider ignore the box layer, so that they can keep moving together.

avatar image TSRajesh · Aug 07, 2013 at 02:19 AM 0
Share

@aria,

  • To avoid that (i.e avoid the box getting bumped around), you need to mark it as $$anonymous$$inematic (Not respond to "normal" physics)

  • To ignore collision between two colliders, you don't need a layer. You can just use Physics.IgnoreCollision()

0 Replies

· Add your reply
  • Sort: 

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

Character Controller can pass through Collider 1 Answer

Character Controller's Collider Restricting Other Colliders 1 Answer

Make Character Controller a Box? 2 Answers

how to detect collision between two character controllers? 1 Answer

Character Controller 2 Answers


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