• 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
Question by Hoofman · Mar 16, 2013 at 11:25 PM · collidercharactercontrollercharacter controllerwalls

Character Controller, changing collider's size?

In our 2d platformer game, we have a trickster character that can change form and size. The Trickster character has a Character Controller (the First Person controller from the CharacterController package). When the trickster changes forms, we change the size of the character controller's center, radius, and height (it's always an upright capsule, I know we can't change that). The code we use is:

 this.GetComponent<CharacterController>().center = formStats.colliderAlt;
 this.GetComponent<CharacterController>().height = formStats.colliderHeight;
 this.GetComponent<CharacterController>().radius = formStats.colliderRadius;

(formStats is just a script with a bunch of variables to change the size / form of the Trickster).

Here's the problem: if the collider changes from small (a spider) to large (a fox), there's a chance it can go through walls and floors. We know WHY this happens: when the collider suddenly gets bigger, it extends beyond the bounds of the wall ever so slightly. The Character Controller interprets this as going through the wall.

What's the best solution to this problem?

-Find some way to have walls "push" you back when you go from small to large? (no idea how to do this codewise) -Have separate layers for the Large form and Small form? (separate walls depending on collider size) -Just have the collider remain the same size? (which defeats the purpose of having a smaller form) -Some other solution?

Comment
Fattie

People who like this

1 Show 2
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 nsxdavid · Mar 16, 2013 at 11:34 PM 0
Share

Its tough to implement a general solution for this (which is one reason why there is none built in). One thing you can try is to cast rays (or spheres, etc.) in a circle from where the character is standing to try and see if it needs to push a bit before changing the collider size. In complex situations this may fail... such as if it is in a narrow corridor... you gotta ask yourself... what do you want to happen? Because in that case there is no "obvious" answer.

avatar image Hoofman · Mar 16, 2013 at 11:52 PM 1
Share

@nsxdavid Thanks for the suggestion with the sphere, we'll keep that in mind. Narrow corridors aren't too much of a problem as we already have a script that prevents the player from changing to a larger form (we lay down an invisible box around the corridor, if they're within that box they can't change).

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

12 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

Related Questions

How to detect angles of walls? 1 Answer

how to detect collision between two character controllers? 1 Answer

My Character Controller Is Warping Randomly (/w video) 0 Answers

Help with Colliders? 0 Answers

Bomberman like movement 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