• 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 helios · Jun 02, 2011 at 09:07 PM · charactercontrollerrestrictmovement

Player breaking through colliders when trying to restrict Z movement.

I have a player that uses a Character Controller, and a modified version of the SidescrollControl. I want to restrict the Z movement. When I do this by simply setting it's transform z property to 0 on an update, it works until it runs into a collider (lets say a wall). If you keep trying to move into it, it will "break" right through in a fraction of a second and continue on its way. The same thing happens if I try and use a Configurable Joint instead and restrict the Z through there. Does anyone have any idea how to fix this? I feel like there is something obvious I am missing. I've searched and searched and can't find any other people having this issue. Thanks.

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
1
Best Answer

Answer by Owen-Reynolds · Jun 04, 2011 at 06:27 AM

I'm going to guess that setting Z is teleporting it into the wall just far enough that it decides you need to move freely to get unstuck. Say you hit a sphere and slide a little forwards and sideways on it. z=0 snaps it to inside. Same with a slightly crooked wall. Best solution is to lock z-position, but charControllers can't do that.

A brute force hack would be to slap two giant colliders at z=1 and z=-1, and let them keep z around 0 (give a really slippery physics material?)

You could add z movement in the script (moveDirection.z = -transform.position.z) to move it back to 0 next frame, if it gets off.

You might also try having collisions go a tiny bit backwards (transform.position -= moveDirection*0.05 ?) to be sure setting z=0 won't put you inside it.

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 helios · Jun 06, 2011 at 04:10 AM 0
Share

Thank you!! Adding movement.z = -transform.position.z works.

avatar image
0

Answer by Anxo · Jun 02, 2011 at 09:11 PM

try this

 function LateUpdate(){
 if(transform.position.z > 0)
 {
 transform.position.z = 0;
 }
 
 }
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 helios · Jun 02, 2011 at 11:49 PM 0
Share

Thanks for the response, but this doesn't work either. Any other ideas? Getting really desperate over here.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

CharacterController - hard code X-axis movement to limit movement? 2 Answers

Stopping the Character Controller 0 Answers

Detecting collisions with OnControllerColliderHit when not moving 0 Answers

Conflict between CharacterController and NavMeshAgent 1 Answer

Lerp can someone explain please 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