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 H3core · Mar 19, 2013 at 07:13 PM · 2dcharactercontroller

2D Game RigidBody Vs. Character Controller

Hi Unity,

Im working on a 2d game, and came down to the point where i needed to detect collisions by direction, and that lead me to Character Controllers, after playing around a bit i discovered its not practical for my game for several reasons, especially since i rely on forces a lot and that requires a rigidbody, tried using both with disappointing results as they were not meant to be used simultaneously.

My questions is, is there anyway around this issue, such that i can detect collisions without relying in a CHaracter Controller?

Any feedback, suggestions, and obviously solutions are welcome.

Thnx in advance

Cheers :)

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

2 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer Wiki

Answer by tzamora · Mar 19, 2013 at 08:11 PM

For 2d I usually prefer character controllers, because they allow me to do a more manually movement that is more natural for 2d games (like mario or castlevania).

Rigid body is a nice solution but you depend on the physx engine and your tweeks.

If you have a problem with collisions or collision detection, maybe you are not setting the triggers well, or maybe you need some helper methods to work with your character controller

look at this c# extension that returns if the character controller is touching a wall for example

 public static bool isTouchingWall (this CharacterController characterController)
 {
       return (characterController.collisionFlags & CollisionFlags.Sides) != 0;
 }

just like this you could find more helper methods for the character controllers.

Also remember that when using colliders the OnTriggerEnter will only dispath if one collider has its trigger false and the other collider has its trigger in true. (it doesnt matter if is rigid body or character controller)

player.collider | other.collider | OnTriggerEnter will dispacth

trigger=true | trigger=false | yes

trigger=false | trigger=false | no

trigger=true | trigger=true | no

trigger=false | trigger=true | yes

Thats all.

Comment
Add comment · Show 2 · 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 H3core · Mar 19, 2013 at 09:28 PM 0
Share

Thnx, for all your feedback guys been really helpful.

That thread was some amazing piece of work.

And after some thought, a character controller was an obviously better solution.

Thnx again guys

Cheers :)

avatar image fafase · Mar 20, 2013 at 07:23 PM 0
Share

Character controller should be used as long as you are trying stuff like mario. If you want to go for gravity things like walking on the walls and upside down on the ceiling then CC won't do as you cannot rotate the capsule (at least I have not managed) and then rigidbody comes to the rescue as you can do anything with it.

avatar image
1

Answer by xt-xylophone · Mar 19, 2013 at 07:42 PM

Rigidbodies have lots of ways to detect collisions thankfully.

Add a script to the rigidbody you want collisions for and use one of these 3 methods:

OnCollisionEnter: OnCollisionEnter is called when this collider/rigidbody has begun touching another rigidbody/collider.

OnCollisionExit: OnCollisionEnter is called when this collider/rigidbody has stopped touching another rigidbody/collider.

OnCollisionStay: OnCollisionStay is called once per frame for every collider/rigidbody that is touching rigidbody/collider.


Each of them will create a Collision object which has the information:

relativeVelocity: The relative linear velocity of the two colliding objects (Read Only).

rigidbody: The Rigidbody we hit (Read Only). This is null if the object we hit is a collider with no rigidbody attached.

collider: The Collider we hit (Read Only).

transform: The Transform of the object we hit (Read Only).

gameObject: The GameObject whose collider we are colliding with. (Read Only).

contacts: The contact points generated by the physics engine.


Hopefully you can use that information to handle any kind of complex collision detection you need :)

check out:

http://docs.unity3d.com/Documentation/ScriptReference/Rigidbody.html http://docs.unity3d.com/Documentation/ScriptReference/Collision.html

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 H3core · Mar 19, 2013 at 07:54 PM 0
Share

I guess my main question was misleading.

$$anonymous$$y concern is the use of the collision flags such as above and below that are a part of the Character Controller, thats what im after really.

Is there anyway to achieve that without a Character Controller?

Thnx

avatar image tzamora · Mar 19, 2013 at 08:07 PM 1
Share

http://forum.unity3d.com/threads/99988-I-made-a-collisionflags-script-for-rigidbodies

avatar image xt-xylophone · Mar 19, 2013 at 08:14 PM 0
Share

I suppose with the collision info you "could" calculate all the things you need akin to the controller, otherwise ^ boom! tzamora seems to have it

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

13 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

Related Questions

2D rigidbody movement & walls 2 Answers

A node in a childnode? 1 Answer

Need help with screen resolution and character size 1 Answer

Glitching between box colliders. One is kinematic... Help! 1 Answer

A Question about sprites 3 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