• 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
14
Question by rocket5tim · Nov 24, 2009 at 01:27 AM · animationphysicscharactercontrollermoving-platformmove-with-moving-platform

CharacterController falls through or slips off moving platforms

I made an animated elevator/platform by creating an animation in Maya and then attached a box collider as a child of the animation so that they move together. However my player uses the CharacterController and it falls thru the box collider (floor) as soon as the elevator starts animating*.

There are a couple of threads on the unity forum (here and here), but one of them is very old and neither of them has current or clear explanations of why the CharacterController has issues with attaching to moving objects and how best to solve the problem.

*note if I keep the player moving while the elevator is in motion, he does not fall thru the floor - he only falls thru when standing still. Also he's more likely to fall thru while the elevator is moving up than down.

Comment
Add comment · 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 ecameracci · Jul 23, 2015 at 11:17 PM 0
Share

I found this video helpful https://www.youtube.com/watch?v=U1Uk$$anonymous$$w12pQo

avatar image Michiyuki13 · Oct 15, 2015 at 09:45 AM 0
Share

Hey guys, that simple JS parenting script worked in my case, thanks!!! :D

However, I have noticed that it works much better with my animations imported from $$anonymous$$aya (or perhaps it's the mesh itself,and the trigger box generated from that mesh (it's just a duplicate)). The collider is set to convex,otherwise it wouldn't let me check 'is trigger' box.

Another moving platform was created with a Unity's cube and the trigger cube was done the same way,uses animations created with $$anonymous$$echanim, and whenever my character steps inside the trigger zone, its feet start sinking in a bit... I'm using that standard Ethan char to run around the level.

$$anonymous$$aybe this observation can help somebody out with the similar issue. I guess I need to test with another object imported from $$anonymous$$aya.

A programmer friend is going to help me with this in the next couple of days,I know parenting is not the best solution,but the other ones are too complicated for me (game artist here xD). If he does something cool,I'll post it here!

9 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by moinchdog · Jul 30, 2012 at 08:33 AM

you could just animate the Player with the Elavator and It will be forced to move with the Elavator

Dj

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
avatar image
1

Answer by venkspower · May 04, 2012 at 04:17 AM

Why don't you just make the CharacterController as the child to the floor of the elevator. That solves it. Simple!

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 WhendricSo · Nov 10, 2016 at 09:08 AM 0
Share

No, it doesn't. Perhaps actually testing your solution ins$$anonymous$$d of blurting out the first thing that pops into your head would be more useful.

avatar image
9

Answer by Codayus · Mar 16, 2010 at 12:59 AM

There's several ways to do this of various complexity, depending on what you need. For a simple elevator, you probably want the simplest and easiest way - which would be as follows:

  • Create a new cube game object which is a child of your elevator platform.
  • Give the cube a collider component and set it as a trigger
  • Adjust the size of the cube so that it more-or-less covers the entire floor of your elevator. Y-axis doesn't much matter, but it's important that anyone standing on the platform must be inside the trigger.
  • Disable the mesh renderer component.
  • Create a new .js script with the following code in it and add it to the trigger collider:

    function OnTriggerEnter (other : Collider) { other.transform.parent = gameObject.transform; } function OnTriggerExit (other : Collider) { other.transform.parent = null; }

    What's happening here is fairly obvious. When anything enters your trigger (like, for example, a CharacterController), it becomes parented to it. Anything parented to the trigger will move when the elevator does. When you step out of the trigger, the parent link is removed. Simple. :)

    Comment
    Add comment · Show 11 · 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 Deise · May 12, 2010 at 01:32 PM 0
    Share

    thank you! This way is simple but very effective. It is ideal for me because I did not have to change anything else.

    avatar image 0V3RWR173D · May 29, 2010 at 04:57 AM 0
    Share

    Thank you very much for the advise, ALTHOUGH I have encountered a problem. I'm not sure if you are an expert at unity3d but I have a firstpersonplayer with weapons. The weapons are attached to the main camera but when I step on the platform, it does not move correctly with the camera. It will not stay in an exact position relative to the camera. Do you have any ways of fixing this kind of problem?

    avatar image James 2 · Jul 27, 2010 at 10:52 PM 0
    Share

    I looked forever to find how to do this!!! You made it so simple! Thanks!

    avatar image munaeem · Nov 10, 2012 at 09:36 PM 0
    Share

    problem !! my 3d player looks liked he has been just came out from toilet or been squeezed but a roller truck.

    avatar image moinchdog · Nov 11, 2012 at 01:23 AM 1
    Share

    in the script make sure you reset the players transform.localScale to 1,1,1 or else it will be squished

    Show more comments
    avatar image
    7

    Answer by Brian-Kehrer · Nov 24, 2009 at 02:45 AM

    The CharacterController is very simple in function.

    Every FixedUpdate it applies the Move() function to determine where it should go. Typically, gravity is assigned, so it always attempts to move down. The Move() function detects objects between the controllers current and intended positions, and will stop moving when a collision is detected. Of course it's much more complex than that, but that is the idea.

    However, if between calls to Move() in FixedUpdate, you move the ground above the current position of the CharacterController, the check the CharacterController performs will say "There is nothing below me" and so it will fall. Makes sense.

    Now, onto fixing it.

    First, to make things behave well, one trick is to make sure all objects the CharacterController interact with are also being adjusted in FixedUpdate. Animations will run in Update. I would suggest animating the platform in code rather than in Maya, and also in the FixedUpdate loop. While there are ways to make what you suggest work, I think it will be far less complicated in this manner.

    Depending on your game logic, there are a few options. Personally I dislike parenting the CharacterController to other objects because it can result in some strange behavior. Instead, create some code to tell the CharacterController when it is interacting with a moving platform, and allow the moving platform to tell the CharacterController how far it should move this frame, and then reposition the CharacterController manually.

    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 Jessy · May 15, 2010 at 04:09 AM 0
    Share

    I have code that moves a Character Controller to another place on the map, and it may be inside of a collider that it should ins$$anonymous$$d be walking on, afterwards, so it can then fall through. The teleportation happens in OnTriggerStay(), so I don't think there's anything to be helped in terms of FixedUpdate(). Any tips? You think the solution is an OnTriggerStay() in the floors that it can teleport into, which pushes the Controller out far enough so that it's on top again?

    avatar image Brian-Kehrer · May 17, 2010 at 04:30 PM 0
    Share

    Is OnTriggerStay even being called? If you teleport in, it might get messed up. What I finally ended up doing was very complicated. I used a dummy rigidbody specifically to catch that case. Obviously if you are very far off, it will still fail, but it might catch close cases.

    • ‹
    • 1
    • 2

    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

    23 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 avatar image avatar image avatar image avatar image avatar image avatar image

    Related Questions

    Question about pushing objects, "Animate Physics" and Rigidbodies 0 Answers

    Problem with moving (animated) platforms. need script to keep player object on 1 Answer

    How to have CharacterController interact with Object 1 Answer

    What is the easiest way to push a character controller with a moving platform? 0 Answers

    Keeping the player on a moving platform? 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