Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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
2
Question by nreina · May 21, 2019 at 11:04 AM · movementplayercharactercontrollerplatformfalling

Moving Platform and CharacterController.Move not working. The player falls

I am using CharacterController.Move to move the player, and I make the player child of the moving platform to move with it, but it is not working, the player doesn't move with the platform.

 private void OnTriggerEnter(Collider other) 
     {
         if (other.tag == "Platform") 
         {
             transform.parent = other.transform.parent; 
         }
 }
 private void OnTriggerExit(Collider other) 
     {
         if (other.tag == "Platform") 
         {
             transform.parent = null; 
         }
     }

This up code works well, the player change and takes the platform as parent. But the player falls, and not moving with the platform.

   if (Control.isGrounded)
         {
 
             MoveDir = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); 
             MoveDir *= Speed; 
             JumpCount = 0; 
         }
         else 
         {
             MoveDir = new Vector3(Input.GetAxis("Horizontal") * Speed, MoveDir.y, Input.GetAxis("Vertical") * Speed);
         }
         if (Input.GetButtonDown("Jump") && JumpCount < TotalJumps) 
         {
             JumpCount++;
             MoveDir.y = JumpSpeed;
         }
         MoveDir.y -= Gravity * Time.deltaTime;
         if (ActivateMove)
         {
             if (MoveDir != Vector3.zero)
             {
                 Control.Move(MoveDir * Time.deltaTime);
             }  
         }

This is the player moving script. I put a boolean "ActivateMove" to desactivate the movement and check, if is desactivate the player moves with the platorm and it works. But I can't desactive the movement when the player is in the moving platform becouse I want to move it in the platform too.

Thank you.

Comment
Add comment · Show 5
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 Meishin · May 21, 2019 at 12:07 PM 0
Share

Hi @nreina, what's your CharacterController.$$anonymous$$ove method implementation ?

avatar image nreina Meishin · May 21, 2019 at 04:39 PM 0
Share

Sorry, don't understand

avatar image Meishin nreina · May 21, 2019 at 05:06 PM 0
Share

From what you wrote, assu$$anonymous$$g colliders / rigidbodies are correctly defined, your code could/should work (i don't really get why you're setting $$anonymous$$oveDir.y -= Gravity * Time.deltaTime all the time but it shouldnt matter much if your character jumps on a platform with a collider/rigidbody)

So then it depends how the $$anonymous$$ove method is defined in your CharacterController class (it is not a Unity API class/method)

It would help to see the definition of the $$anonymous$$ove method your using

Show more comments

3 Replies

· Add your reply
  • Sort: 
avatar image
4
Best Answer

Answer by nreina · May 22, 2019 at 08:06 AM

I finally made it, Changing the Platform code from Update to FixedUpdate, it works well. I don't know why, but works. Searching I found the solution here: https://answers.unity.com/questions/1632526/character-controller-doesnt-move-with-a-moving-par.html

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 nreina · May 22, 2019 at 10:27 AM 1
Share

thanks @$$anonymous$$eishin @DCordoba for the help

avatar image AdiRishi · Jun 07, 2020 at 01:25 PM 0
Share

Thank you! This worked for me. Though I have no idea why keeping the code in Update() won't work.

avatar image
7

Answer by golaod · Jun 09, 2021 at 07:59 PM

It's an old topic, but I just had the same issue. I moved my old project to new unity and new render pipeline system and same script, same player and same platform stopped working.


For me changing from Update to FixedUpdate was not the right solution as other triggers on the platform stopped working properly (they worked, but...during specific frames only?).


After checking all the topics with rigidbody, OnTriggerStay, position correction and so on, I found out that there is 'auto sync transforms' option which was not enabled in my new project. When I reenabled it, things went back to normal. (Edit -> Project Settings -> Physics (or Physics 2d) -> Auto Sync Transforms

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 Helldubs · Aug 30, 2021 at 06:20 PM 0
Share

Thank you so much. I literally wasted a whole day trying to get this to work, when it was just a simple setting in unity...

avatar image Yrisel · Mar 13 at 02:27 PM 0
Share

You have no idea how much I was searching for a solution, I didn't know my problem was in the Physics settings.

Thank you so much!

avatar image awsapps · Apr 11 at 08:29 PM 0
Share

Man you're a life saver, 1) I move the platforms with dotween, so I Changed all my tweens to fixedUpdate without luck. 2) Stopping the player movement (don't calling the CharacterController.move(direction) ) makes the moving platform to work.

So I realize that, if I simply avoid the Move function if the user doesn't input any key, the platform should work as expected.

After some time, I realize that this will make the player unable to jump, and the gravity won't work on it, because I'm not moving at all.

Blah blah blah, more tests , blah blah blah.... Maybe changing all my code so the player is controled by a RigidBody instead of the Character controler? I had previous projects with movind platforms on rigidBodies and it should work! mmm but this way, you loose the slope control witch is a PAIN to do it on a rigid body... Blah blah blah, more tests , blah blah blah....

AAAND all that was a waste of time, because what I had wrong was a Unity physics settings.

Thank you so much!

avatar image klay03 · Apr 12 at 05:04 AM 0
Share

Turning on 'Auto Sync Transforms' seems to work for me also, I have tried it before so I am sure that ticking that option really does work, though I strongly advise to use the option cautiously as stated here.: https://docs.unity3d.com/ScriptReference/Physics-autoSyncTransforms.html

avatar image
1

Answer by unity_I8FaTX-tZFc4lA · Feb 18 at 10:09 AM

The reason why it is not working it's because you are not saving the transform to the physics engine.

https://docs.unity3d.com/ScriptReference/Physics.SyncTransforms.html

If you have Physics.autoSyncTransforms enable, which is not by default, could also be a potential fix. Otherwise, "When set to false, synchronization only occurs prior to the physics simulation step during the Fixed Update." which explain why the solution you found works.

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

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

Related Questions

Animated platform and twitching player 0 Answers

How can I convert LOCAL transform.forward to WORLD Vector3? 2 Answers

Tweaking character movement 1 Answer

How to hold objects in third person? 1 Answer

Problem with moving my player whilst in the air 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