Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
3
Question by Skjalg · Jun 24, 2011 at 12:31 PM · rigidbodyplatformermoving-platformmove-with-moving-platform

Rigidbody on a moving platform

Hi.

I am currently redeveloping our character-controller based player into a rigidbody-based player for Pirates of New Horizons because we got some strange behaviors when switching to unity 3.x from 2.6.

We figured we would have more control if we did things ourselves.

However, I am struggling with having our player be moved by other rigidbodies. More specifically; moving platforms that are underneath the player. The player will be pushed sideways if something hits it from the side, or moved upwards if something underneath pushes upwards, but I cant seem to figure out how a platform moving in the x-z plane can move the player, which is a rigidbody, standing ontop of it.

On the old character controller I had implemented the solution that can be found here: http://answers.unity3d.com/questions/8207/charactercontroller-falls-through-or-slips-off-mov.html but since all the rigidbody movement is applied during FixedUpdate, this isn't working so well.

Does anyone know how I can approach this problem without parenting to the stuff below, because that feels very jerky when I have tried it.

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

6 Replies

· Add your reply
  • Sort: 
avatar image
5

Answer by Lanthuas · Dec 26, 2017 at 03:02 AM

Just add script with this code to platform. Works like charm for me.

     void OnCollisionEnter2D(Collision2D other) {
         if (other.transform.tag == "Player") {
             other.transform.parent = transform;
         }
     }
 
     private void OnCollisionExit2D(Collision2D other) {
         if (other.transform.tag == "Player") {
             other.transform.parent = null;
         }
     }
Comment
Add comment · Show 4 · 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 lyn-ith · Jan 10, 2018 at 05:05 PM 0
Share

hey, when i set my player as a child of the platform, it does follow the platform, but i cant move the player if the platform is moving. its as though the controls were disabled... (im using rigidbody.moveposition for player movement) any idea why that might be? thanks in advance!

avatar image lyn-ith lyn-ith · Jan 10, 2018 at 05:21 PM 0
Share

fixed it. i called moveposition () from update () ins$$anonymous$$d of fixedupdate ()

avatar image Content1of_akind · Apr 06, 2019 at 07:42 PM 0
Share

Thank you, the player is moving with the platform and most importantly the player is still able to move. $$anonymous$$uch Appreciated.

avatar image Haneferd · Jul 30, 2019 at 06:30 PM 0
Share

Thanks. I used your approach now on an elevator, but replacing Enter and Exit with Stay. Work very well. I also had the issue with both enemies and player not "following" smoothly the elevator.

avatar image
4

Answer by hannesdvl · Mar 09, 2013 at 06:03 PM

Moving the platform using only Rigidbody.MovePosition and Rigidbody.MoveRotation in FixedUpdate fixes slipping/bouncing and gives a very smooth and accurate simulation.

Check the full answer in this question: http://answers.unity3d.com/questions/167404/rigidbody-on-a-platform.html

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 Content1of_akind · Apr 06, 2019 at 07:41 PM 0
Share

Thank You, the frames are smoothed out.

avatar image
3

Answer by thebyus · Jan 06, 2013 at 07:19 AM

I know this is an old thread, but I will answer here anyway, as I have been looking to do essentially the same thing for a while and finally figured it out.

I've been messing around with this for the better part of 3 months. I have a rigidbody WIHTOUT a character controller. I have a character that I need to be able to roll onto and off of moving platforms, so parenting wasn't really an option, and the character controller didn't really allow me to do some of the other things I have going on in the game. The answer I found was to create PhysicsMaterial like was mentioned above. I pretty much maxed out everything to do with friction (either 1, Maximum, or for open ended options, 100,000) and set bounciness to 0 or Min. Make sure to set the FrictionDirection2 in the X and Z axes again, (100,000). Then I added this PhysicsMaterial to the box collider on the platform, and finally, I added a rigidbody to the platform, set the mass at between 100 and 1000 (depending on how it plays) set the Rigidbody to "Is Kinimatic", turned off gravity zeroed everything else out and then played with the velocity of the platform to keep the Character from tipping over. After 3 months, the real key here was adding the Rigidbody to the platform, without it nothing happens (and I have the mass of my Character set to 100,000 on it's rigidbody, so a little platform mass goes a long way!) Good luck!

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 Lukas_GMC · Feb 25, 2013 at 11:49 PM 0
Share

Anyone doing a platformer should know not to use a CharacterController. I've been working on a 2d platformer and my controls are pretty solid on static platforms. But I get random jitters on moving platforms. The positions appear to be correct and the jitters appear more when the platform moves up or down. For my player movement: playerRB.velocity = m_velocity + platform.GetComponent().velocity I'm basically not using any of the physics provided by a rigidbody but I needed more freedom over my character that a standard CharacterController couldn't offer. Any ideas on how I can fix my jitter?

avatar image
2

Answer by Waz · Jun 26, 2011 at 01:33 PM

Have you tried tweaking the PhysicMaterials you are using, and increasing the contact points (eg box not capsule), such that friction does the work for you? That's the real-world answer to your question.... not that game physics is perfect of course! Also be careful of the drag setting on the player RB. Also be careful how you move the platforms. Anyone will slip over if the floor beneath them accelerates from 0 to 1m/s in 0.01 seconds.

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 Skjalg · Jun 26, 2011 at 01:43 PM 0
Share

I played around a little bit with the physic materials, but haven't really delved into that just yet. As with all game characters I'm not really after 100% real physics for my main character, I just want him to be able to be moved by floating platforms :)

avatar image Zaddo67 · Mar 01, 2014 at 01:24 AM 0
Share

This works perfectly. I added a box collider and turn it on when I am on a platform.

avatar image
1

Answer by Azaldur · Sep 26, 2011 at 06:56 PM

Hey Skjalg, did you already found out how to make a player move fine on a moving object? I'm also struggling with this.

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 Skjalg · Oct 22, 2011 at 05:22 PM 1
Share

After about a week of trying different things I figured that creating a player controller by using a rigidbody is impossible to get to feel good unless you set the velocity each frame. And when you start setting the velocity every frame you are basically rendering the whole rigidbody physics stuff obsolete and you might as well use the Character Controller ins$$anonymous$$d. So I switched to that.

  • 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.

Follow this Question

Answers Answers and Comments

15 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

Related Questions

Stay on Moving Platform without Character Controller 1 Answer

Keeping the player on a moving platform? 0 Answers

Make a Platform push a character controller? 2 Answers

CharacterController falls through or slips off moving platforms 2.0 2 Answers

What is the easiest way to push a character controller with 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