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 casimps1 · May 26, 2012 at 01:03 PM · collisionmovementcharactercontrollerslope

How can I guarantee a CharacterController never leaves the ground?

I have a CharacterController and I am trying to make absolutely certain that it never leaves the ground. More specifically, that it never leaves the y=0 plane.

The collision in the scenes are mostly at 90-degree angles (flat ground at y=0 and upright walls), but occasionally there are some places where collision is sloped (for example, a wooden pallet leaning against a wall). These areas of sloped collision are the problem. I want it such that if you try to move the CharacterController into that sloped collision, it doesn't climb or step on it in any way. But regardless of what I've tried it still climbs up this slope.

And actually the climbing behavior is a little odd. If I just try to move gently into the slope, it stays on the ground and doesn't climb. I can try moving more forcefully into the slope (i.e. - call CharacterController.Move() with a greater magnitude Vector3) and eventually the CharacterController will pop up and be standing about halfway up the slope.

I've set StepOffset to 0 and SlopeLimit to 0. I also make sure that every time, before I call CharacterController.Move(), the Vector3 I send in has a y-component of 0.

Is there any way to keep this from happening?

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
0

Answer by whydoidoit · May 26, 2012 at 03:57 PM

Firstly I'm no expert on CharacterController but this might help you... You could try attaching a script that forces the character back to the previous seen location with Y coordinate 0 - i.e. step back to the last valid position if you are in an invalid position:

 var lastValidPosition : Vector3;

 void Start()
 {
      lastValidPosition = transform.position;  //Hopefully the starting point is valid!
 }

 void LateUpdate() {
     if(transform.position.y != 0)
          transform.position = lastValidPosition;
     else
          lastValidPosition = transform.position;
 }
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 casimps1 · May 29, 2012 at 05:20 PM 0
Share

Yeah, this is basically the workaround that I had been using in the meantime. I hate this kinda stuff though because it feels so hacky to me.

Ultimately, I suspect that it is some odd bug with Unity physics and collision, but this workaround seems to be fine for now.

avatar image whydoidoit · May 29, 2012 at 05:24 PM 0
Share

Well you could certainly say that it's a rule your system clearly defines, hence not a hack - but I know what you mean, you would like that no climbing thing to work with the parameters you supply.

avatar image
0

Answer by Owen-Reynolds · May 27, 2012 at 04:08 PM

A non-programming approach would be to add some big box colliders to wall off the areas. A trick, if you have to place several adjoining, is to use a Unity cube, size it to the area, then click off the render. Can remove the mesh components when you are sure they are placed.

If you have other objects that need to pass through the area, you can set the colliders to only block the player: in Layer->AddLayer put something like playerWall in slot 8+. Then select playerWall for all those walls. Then add another layer "player" (maybe in slot 9) and put the player on that. Finally, in Edit->ProjectSettings->Physics, check off the playerWall boxes for everything except player (go down the playerWall column, and across the playerWall row, leaving only the box that crosses player checked.)

If you also have raycasts going into the area, those can be fixed to also ignore playerWall, but by then maybe a code-based solution is better.

Comment
Add comment · 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

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

3D Character controller jittering when jumping against a small wall 2 Answers

How to Logically Match Ground Slope While Using This Code? 1 Answer

Using rigidbody for collisions only, not movements? 1 Answer

How to hold objects in third person? 1 Answer

issue applying vector for slope sliding 0 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