Unity Moving Platform Tutorial

Поділитися
Вставка
  • Опубліковано 20 сер 2024
  • In this Unity video I show how to implement a moving platform for a thirdperson player (works for FPS as well), a C# Script, Unity animations and Unity 2018.
    See my social profiles here
    G+: plus.google.co...
    Twitter: / jayanamgames
    Facebook: / jayanamgames
    Patreon: / jayanam
    Indiegogo: / jayanamgames
    Production Music courtesy of Epidemic Sound: www.epidemicsou...

КОМЕНТАРІ • 354

  • @stealthdick
    @stealthdick 2 роки тому +79

    Great tutorial, for the people using a character controller that are having their characters not transform with the platform there's a simple fix!
    (Edit -> Project Settings -> Physics (or Physics 2d) -> Auto Sync Transforms
    Newer versions of unity don't have Auto Sync Transforms enabled, so check the box and watch your code work!

  • @bigdogweedsmoker
    @bigdogweedsmoker 4 роки тому +73

    I've seen a lot of people having problems with their character only slightly moving with the platform or not at all. The trick is in the animator, make sure that the Animator attached to the platform that is moving, has the "Update Mode" set to Animate Physics. That should hopefully resolve your issue.
    Edit#1: Fixed some grammatical errors
    Edit#2: This should resolve your issue if you are using a CharacterController, and want to use moving platforms in your game

  • @Snowerzzz
    @Snowerzzz 5 років тому +34

    Thank you man honestly... you explained this in only 7 minutes like a pro. Keep it up :)

    • @JayAnAm
      @JayAnAm  4 роки тому +7

      Thx will do... but hey: I AM a Pro:-)

    • @weluvsprxng
      @weluvsprxng 3 роки тому

      @@JayAnAm don't push it, that's risky..

    • @ghadaghadoosh6496
      @ghadaghadoosh6496 3 роки тому

      @@JayAnAm
      Can you understand Arabic?
      I want's describe my problem in Arabic.

    • @JayAnAm
      @JayAnAm  3 роки тому

      @@ghadaghadoosh6496 No, sorry

    • @ghadaghadoosh6496
      @ghadaghadoosh6496 3 роки тому

      @@JayAnAm
      I want to be a planned paper on his paper and be wrapped then open this chart for a certain

  • @Gyvulys
    @Gyvulys 4 роки тому +6

    I've been racking my brain all day long, trying to find a way to smoothly move an elevator up and down with pauses, using Code. And then I stumbled onto this video, that solves this issue so easily using Animations...

    • @JayAnAm
      @JayAnAm  4 роки тому +1

      Hey, great it helped!

    • @Gyvulys
      @Gyvulys 4 роки тому

      @@JayAnAm
      It helped immensely. Thank you for the video man :)

  • @Gyvulys
    @Gyvulys 4 роки тому +9

    Note: For anyone, who gets a glitch where your player unit gets stretched/warped when parented:
    > Place your MovingPlatform inside a Parent - empty game object with rotation {0,0,0} and scale {1,1,1}.
    > Place your script itself on the MovingPlatform, not the Parent. Add the Trigger Box Collider to MovingPlatform as well.
    > Move (Animate) the Parent, rather than the platform itself.
    ( _You can make this easier, by first making a Cube and animating it. Then, remove all the components _*_except Transform and Animator_*_ - making it an empty, invisible object_ )
    > Make that empty Parent object a parent of player as well, same way as it's shown in the video.
    The problem is caused by the fact, that if you Parent an object, that object will receive rotation and scaling of the parent. Which is why we cannot directly use the MovingPlatform as parent of the player. We need an object of rotation 0 and scale 1 to parent both our MovingPlatform, and the player.

    • @mikethegamedev
      @mikethegamedev 4 роки тому

      ok

    • @romeobassin2524
      @romeobassin2524 3 роки тому

      thanks!

    • @sachinkankane9877
      @sachinkankane9877 2 роки тому

      Bro how to fix shaking jittering effect when our player move with Moving platform

    • @knightoftheblood1841
      @knightoftheblood1841 Рік тому

      actually you can solve this with simple code:
      player.transform.SetParent(movingObject, false); ---> "false" will disable resizing the player

    • @xXxVentrilloxXx
      @xXxVentrilloxXx Рік тому

      worked!!! you the goat mane

  • @ggentertainment2737
    @ggentertainment2737 4 роки тому +1

    the thing with the player moving with the platform is something that a lot of games forget and in my opinion, it is a very important thing in making your game more enjoyable!

  • @clarkmeyer7211
    @clarkmeyer7211 2 роки тому +1

    this was really helpful. I want to make ships and I wasn't sure how I was going to make players stay on the object while the ship moved. as soon as you added that trigger I knew what you were going to do with OnTriggerEnter/Exit and once you did it then it all made sense. Thank you so much

  • @ajo3300
    @ajo3300 Рік тому

    I have been stuck on this for so long and I am so grateful someone directed me to this video. Thank you so much!!!

  • @elsenussi
    @elsenussi 3 роки тому

    Thanks brother , you saved my life, the script works perfect

  • @codinginflow
    @codinginflow 3 роки тому +4

    Great, the 2nd box collider with the trigger was the missing piece for me, because otherwise the player would also stick to the sides of the platform 👍

  • @a3dadventure79
    @a3dadventure79 Рік тому

    your tutorials are lifesavers. thanks for being awesome

  • @SeaforePerl
    @SeaforePerl 5 років тому +1

    Wow! Very good, eloquent and simple script that does exactly what I was wanting! (I am using it for a rather intensive VR project, so a challenge keeping my balance, but a very good way to get the effect I wanted!)

  • @thiloaron3378
    @thiloaron3378 3 роки тому +2

    OMG! I didn´t know that this is sooooo easy....
    I love your videos, bro!

    • @JayAnAm
      @JayAnAm  3 роки тому +4

      Glad you like them!

    • @thiloaron3378
      @thiloaron3378 3 роки тому +2

      @@JayAnAm Can you help me? The Attach-BoxCollider doesn´t work... Thescript is correct, Is Trigger is true... I CAN´T FIND THE MISTAKE

  • @petergalowicz3420
    @petergalowicz3420 Рік тому

    omg tysm im making a vr game but im new to unity and after 2 days of being confused this video worked

  • @edoardobarolo4680
    @edoardobarolo4680 5 років тому +6

    that's what I was looking for THANK YOU SO MUCH !!

    • @JayAnAm
      @JayAnAm  5 років тому +1

      So great it helped!

    • @edoardobarolo4680
      @edoardobarolo4680 5 років тому

      @@JayAnAm mmmm but I have issues for a circle moving platform.. When I go right the character put itself in jump position then it stops... After a while it falls from the platform...

  • @EdgeGMike
    @EdgeGMike 2 роки тому

    Thanks man I was not understanding why my script didn’t work I had to connect the player to the script super helpful

  • @sarahkhamassi3888
    @sarahkhamassi3888 6 років тому +3

    Thanks a lot that helped so much , really appreciated your short and super clear video , subscribed ^^' !

    • @JayAnAm
      @JayAnAm  5 років тому

      Cool, thank you

  • @Racools
    @Racools 5 років тому +5

    If you have a problem where the player is getting distorted then take you platform and put it in an empty gameobject that has a scale of 1 or the same scale of your player then add a box collider to that empty object

  • @Hiromu656
    @Hiromu656 2 роки тому

    This worked perfectly even for going Up and Down. Thank you.

    • @swanky9855
      @swanky9855 25 днів тому

      hey hiromu656, didn't think I'd see you here, just read you're newest update today. Can't wait for Thief's Roulette!

  • @sidaodograu2950
    @sidaodograu2950 5 років тому +1

    This works perfectly. Thanks, it's so simple and effective. Nice Joob, good video!

  • @elizabethcstudios8703
    @elizabethcstudios8703 4 роки тому +8

    This is a great tutorial the only downside is that somehow my cube character is being warped. every time my character rotates or jumps to a new platform it slowly goes from a regular rectangle to a very thin and wide rectangle. Edit: this was my fault my model wasn't in a 1,1,1 scale

  • @Mrazgoodaz
    @Mrazgoodaz 3 роки тому +4

    Is this working with 2020 version? Tried exactly what's shown in the code although the player doesn't move with the platform.

    • @Mrazgoodaz
      @Mrazgoodaz 3 роки тому +1

      Edit: Nevermind, just put the animation to 'Always Animate.'

  • @betweenwonders1819
    @betweenwonders1819 4 роки тому +1

    THANK YOU SO MUCH! you've made it so clear and easy!

  • @MLaurenavicius
    @MLaurenavicius 2 роки тому

    Straightforwardly beautiful! Thank you!

  • @Brotality
    @Brotality 4 роки тому +9

    I am having a problem where my character parents to the platform and moves with it, but only at a fraction of the speed of the platform, where they then just fall off. Any ideas how to fix this?

    • @bigdogweedsmoker
      @bigdogweedsmoker 4 роки тому

      Me too, I move my player with the character controller.

    • @mikethegamedev
      @mikethegamedev 4 роки тому

      here you can watch jimmy vegas unparent the platform tutorial ua-cam.com/video/Ni1YOa8AaLg/v-deo.html

    • @ArtrexSt
      @ArtrexSt 3 роки тому

      try to use this Logic:
      private void OnCollisionStay2D(Collision2D collision)
      {
      if (collision.transform.CompareTag("Platform") && playerBody.velocity == Vector2.zero)
      {
      transform.parent = collision.transform;
      }
      else
      transform.parent = null;
      }
      i using this logic on my **PlayerScript**
      and I still don't know if it will cost a lot of processing

  • @johngibbon9784
    @johngibbon9784 3 роки тому +1

    Really useful - solved my elevator 'problem' :)

  • @munyamunya313
    @munyamunya313 3 роки тому +2

    bro i have a problem my player start shaking when goes crazy when he goes on the platform
    sorry man its working fine now i just made a new platform and its working okay

  • @iamlovelesh
    @iamlovelesh 4 роки тому +3

    The Platform is not moving in Play Mode but it is running well in Animation Mode

  • @ggentertainment2737
    @ggentertainment2737 4 роки тому +10

    when doing this my object stretches? anyone got a similar problem?

    • @GENERAL9612
      @GENERAL9612 4 роки тому +1

      Welcome to the club! My sphere gets stretched out. I will present this as a feature, not a bug.

    • @O1dBay
      @O1dBay 4 роки тому

      Same

    • @ggentertainment2737
      @ggentertainment2737 4 роки тому

      @@O1dBay so this isn't really a solution but in my project, I didn't animate it but I'm moving it with a script (this adds more control when the animation should stop etc.) so I just said that anything touching the object (or it's trigger) should have the same movement applied to them (so I'm kinda programming parenting)

    • @O1dBay
      @O1dBay 4 роки тому

      GG Entertainment I’ll try that, thanks for the suggestion.

    • @arkalexx
      @arkalexx 4 роки тому

      yes I had the same problem use a platform without scale

  • @rkgamesstudio6977
    @rkgamesstudio6977 3 роки тому +2

    This helped me a lot

  • @maif3ng
    @maif3ng Рік тому

    Some I greatly need without coding for the platform's animation

  • @buddyroach
    @buddyroach 3 роки тому +1

    it kinda works. but player slides so doesnt move with platform completely. not using animator. moving block with its own script moving its vector.

  • @018FLP
    @018FLP 3 роки тому +1

    Awesome! Workd like a charm!

    • @JayAnAm
      @JayAnAm  3 роки тому

      Great to hear!

  • @kozmobotgames
    @kozmobotgames Місяць тому

    It is not working for me. My character that uses CharacterController does not stick with the platform.

  • @cope4423
    @cope4423 4 роки тому +17

    It parents the player to the platform, but still just slides off.

    • @yetilee
      @yetilee 4 роки тому

      I have that same issue

    • @notcomfy
      @notcomfy 4 роки тому

      @@yetilee were you able to resolve the issue?

    • @yetilee
      @yetilee 4 роки тому

      @@notcomfy no I have not, I tried upgrading my unity project to a newer version and now several other things are broke on my project because of that haha.

    • @scottmcphail2511
      @scottmcphail2511 4 роки тому +1

      okay so he has another much more recent video ua-cam.com/video/wwxdqdSbYds/v-deo.html
      apparently this script does not work with certain types of character controllers

  • @zzoinks
    @zzoinks 4 роки тому +1

    Yay! This worked for me, thanks so much.

  • @lobster1781
    @lobster1781 3 роки тому +2

    I've done a moving platform going side to side, but when I tried to do it up and down it wouldn't loop. Anyone know how?

  • @toxicinc763
    @toxicinc763 5 місяців тому +1

    this is what i though before watching the tutorials this only uses animation and this is the most easies tutorials and thanks this is useful 👌and while i was browsing i saw something called lerping 🤣 so i not going thereeee

  • @AlejoElGunner
    @AlejoElGunner 4 роки тому

    Thank you bro works like a charm

  • @neohaydar4242
    @neohaydar4242 3 роки тому

    THANK YOU FOR CREATING THIS VIDEO! BECAUSE I HAVE THIS PROBLEM!

  • @ProyectoPandanejo
    @ProyectoPandanejo 2 роки тому

    Perfect and simple. Thank you

  • @automaticderpz3186
    @automaticderpz3186 5 років тому

    Omg Thank you I have been trying to get this to work for about 20 min until I found your video THANKYOU

  • @detlasthought6067
    @detlasthought6067 5 років тому +3

    could you do a video that does this but with a force with a rigid body?

  • @LizzardKaze
    @LizzardKaze 2 роки тому

    Damn this is a good tutorial. So simple!

  • @pleasedontsub2732
    @pleasedontsub2732 2 роки тому

    I make the player have the platform as a parent but the player gets the components of the platform I don't want it to have like the script attached to the platform and the platform's size

  • @gamesworld4922
    @gamesworld4922 4 роки тому

    Thank you so much for this awesome tutorial

  • @kalabyonas9521
    @kalabyonas9521 4 роки тому

    oh very very very thank you sooo much brother. you really helped me.

  •  3 роки тому

    its sooooo good ! thanks dude

  • @jrgamerelite5287
    @jrgamerelite5287 2 роки тому +2

    Help please my player size als changes when I get onto the platform

  • @localSunMan
    @localSunMan 4 роки тому +7

    Hey Jayanam, thanks for the tutorial, much appreciated!
    I have a follow up question on this:
    When I create a moving platform like this, it works horizontally. When doing a platform that moves either vertically or at a certain degree of diagonally, the movement of the player on a platform becomes janky/jittery or the player stutters while being moved up and down.
    Any idea how to smoothe that movement out? I tried changing the size of the trigger, but if it works for one direction, it doesn't work for the other two.

  • @acewinge2302
    @acewinge2302 3 роки тому

    amazingly explained mate.

  • @gerard7203
    @gerard7203 2 роки тому

    thanks this was great

  • @toonvanaelbrouck1380
    @toonvanaelbrouck1380 4 роки тому +2

    This works for me, left and right, up and down. But when I start using a platform that is rotated, my gameObject warps in the weirdest way and gets rescaled somehow...

  • @DextraVisual
    @DextraVisual 6 місяців тому

    Is there a way to add serialized player list to recognise more than one player jumping on the platform?

  • @littlegreenshell812
    @littlegreenshell812 5 років тому +3

    I have a sphere as my character and when he goes on the platform he moves with it... but he becomes all deformed and gets stretched when the platform moves. Does anyone know how to fix this?

    • @TechnicalAkshay
      @TechnicalAkshay 5 років тому

      answers.unity.com/questions/898093/the-scale-of-my-object-after-parenting-to-a-moving.html

    • @littlegreenshell812
      @littlegreenshell812 5 років тому +1

      Tricky Akshay, Thank you so much!

  • @rizwanshaikh8175
    @rizwanshaikh8175 2 роки тому

    Assets\Scripts\PlatformAttach.cs(15,39): error CS0103: The name 'tranform' does not exist in the current context

  • @waqarbinjamil3577
    @waqarbinjamil3577 5 років тому +1

    How to make it for the Enemy and Player both at same floating cube??

  • @thejouneyman7432
    @thejouneyman7432 4 роки тому +1

    So it works for me, but like some other people in the comments, my player is still sliding slightly. The platform is parenting in steps it feels like. Is there a way to keep the player more rooted to the platform when it moves faster?

  • @atapekuysal
    @atapekuysal 3 роки тому +1

    Thanks a lot

    • @JayAnAm
      @JayAnAm  3 роки тому

      You are very welcome

  • @VitorCaldeira1980
    @VitorCaldeira1980 2 роки тому

    my player didnt stick to the plataform, i have used a first person player

  • @untemi0
    @untemi0 3 роки тому

    rully great idea

  • @max_endourance
    @max_endourance 6 років тому +2

    you are my savior

  • @FloTheUIM
    @FloTheUIM 3 роки тому +1

    Great video, thank you! All works fine accept can't jump off platform, only walk - could this be a box collider issue?

  • @charleschase7945
    @charleschase7945 3 роки тому

    Thanks dude, big help!

  • @whoknowshvh2325
    @whoknowshvh2325 3 роки тому

    i got an problem called expected but can't seem to find it :|

  • @HardGam3r
    @HardGam3r 4 роки тому +2

    Hi can you help me, I made this script and added it on platform, but my character keeps falling off the platform. I'm doing 2d game.

    • @paulmeynckens6676
      @paulmeynckens6676 4 роки тому

      I have the same problem. The player is dynamically moved under the platform in the hierarchy but it is not moving with it.

  • @HaykAmirbekyanTKD
    @HaykAmirbekyanTKD 5 років тому +1

    if you jump up on the moving platform, will you land on it? or will it move from underneath you by the time you land? in real life, you would inherit the momentum of the platform and keep moving at the same speed (not accounting for drag difference between player and platform), so you would land again at the same point on the platform. In this video, you hid that flaw by applying a forward movement to Ethan before jumping, to make him move forward in the same direction as the platform.

  • @marting705
    @marting705 5 років тому

    Great it works for me, thank you so much!!!!

  • @_Hydro68_
    @_Hydro68_ 4 роки тому

    great tutorial

  • @ConchStreetStories
    @ConchStreetStories 5 років тому +3

    does this work for ships?? and what about if there is more than 1 player?

    • @actuallybones
      @actuallybones 5 років тому +1

      If the platform keeps a dictionary of where the GameObject is the player entering the trigger zone, and the "transform" is the parent of the player's transform BEFORE entering the moving platform trigger zone, then you can reassign the original parent to the correct player GameObject onExit

  • @RomualdDubois
    @RomualdDubois 4 роки тому +1

    Life saver, thank you :)

  • @softart5235
    @softart5235 7 місяців тому

    i wonder if it still works with no new input system

  • @jankocnar5390
    @jankocnar5390 2 роки тому +1

    This is solution only works if the platform you are parenting player under has X and Z rotation on 0 and static Y position.

  • @MrJacky
    @MrJacky 5 років тому +1

    Thanks you so much It's realy hepful !! :)

    • @JayAnAm
      @JayAnAm  5 років тому

      Great it helps!

  • @Lufgat
    @Lufgat 3 роки тому

    Very nice video!

  • @rimsha810
    @rimsha810 3 роки тому

    Thank you now my player is moving with platform but it will change the player size what shouldi do to fix it???

  • @pixelysoftgames4500
    @pixelysoftgames4500 6 років тому +3

    hey friend I have a problem and that is when the character collides with the platform deforms the player pd is a rollerball standartassets

    • @sumbanananitro
      @sumbanananitro 5 років тому

      oh men me too, it's weird, any solution?

    • @KreuzDrache
      @KreuzDrache 5 років тому

      @@sumbanananitro Have you checked to see if the platform's collider is set to "Is Trigger"?

    • @slenderblender5711
      @slenderblender5711 5 років тому

      If the parent gameObject scale isn't the same on all 3 axis (1x1x1 for example), any child objects will be distorted. You scripted nothing wrong.

  • @pcpunch59
    @pcpunch59 5 років тому +3

    Dont work with fps controller and unity 2018.3 ?

    • @paulmeynckens6676
      @paulmeynckens6676 4 роки тому

      Same problem with unity 2018.4

    • @JayAnAm
      @JayAnAm  4 роки тому

      ua-cam.com/video/wwxdqdSbYds/v-deo.html

  • @VinnyInTheLab
    @VinnyInTheLab 6 років тому +1

    One issue I'm having is jumping from one moving platform to another, the second moving platform doesn't become a parent of my player so he no longer moves along with the platform, any fixes for this issue?

  • @Blinkers2007GameDev
    @Blinkers2007GameDev 2 роки тому

    absolutely AMAZING!!!!!!!!!!!!!!!!!!

  • @magicaCZ
    @magicaCZ 3 роки тому

    can you send me link to the script? m yvisual studio is not working so i need to download it pls

  • @Monetize
    @Monetize 4 роки тому

    Is there a way to make it get triggered another way when touching the object instead of the "is trigger" option because I have a respawn object using it so when I touch the object it just respawns the player

  • @AlphaLul
    @AlphaLul 4 роки тому

    this doesnt work with physics because the rigidbody overrides the new position. how do you make one that works with physics?

  • @choonjialee4171
    @choonjialee4171 3 роки тому

    what If the platform move vertically?

  • @Khendrall
    @Khendrall Рік тому

    Is there a way to create a prefab of the moving platform with a animation that moves "X" amount to one side and then "X" ammount to the other instead of creating individual animations for each platform?

  • @prankonic4735
    @prankonic4735 3 роки тому

    When I jump off of the platform it deletes the platform altogether. Does anybody know why and how to fix it?

  • @greatone7958
    @greatone7958 5 років тому +1

    My player gets attached to the platform but can't move while on it does someone know how to solve this?

    • @JayAnAm
      @JayAnAm  4 роки тому

      Try this one ua-cam.com/video/wwxdqdSbYds/v-deo.html

  • @cerberus4961
    @cerberus4961 4 роки тому +1

    I'm using a ball player with a sphere collider whenever I jump to the platform my player scale changes, I'm new to game developing so I'm kinda lost, any ideas why this happens?

    • @NishkarshJain
      @NishkarshJain 3 роки тому

      Facing the same problem...did you find any solution??

  • @komiro100
    @komiro100 4 роки тому

    thank you so much !!
    you great !!!

  • @Willskull
    @Willskull 2 роки тому

    Thank you!!

  • @linadragel4118
    @linadragel4118 3 роки тому

    could you please suggest solution. platform between planes moving perfectly, but i cannot step to another platform. i can, if the the "Update Mode" set to Animate Physics (animated platform). but at the same time when i am on 2 static platform character moving with animated platform together(while stading on 2 platform). How can i step up from animated platform and stay on 2 static?

  • @CAESAR_IS_GOD_mohammadisaloser
    @CAESAR_IS_GOD_mohammadisaloser 3 роки тому

    any ideas on why my character warps and resizes when I move on the platform (I am guessing its my character controller?) and also the player attaches to the platform fine and all BUT I animated the moving platform to go really fast at 1 point and at that point in the animation the player just falls off. any way of keeping the player on an extremely fast platform?

  • @seiitkhanotegali7734
    @seiitkhanotegali7734 2 роки тому

    hi can u help me please, im using the rb add force to object that is moving its truck and i want if player could jump and dont fall from it (a player uses character controller).
    thanks, Seit

  • @N1thium
    @N1thium 4 роки тому +1

    Nice work Jayanam! But my player keeps changing the way where he is facing when leaving the platform, any idea? (Im moving my platform in other script apart)

  • @ag1443
    @ag1443 5 років тому

    Hey, im having trouble getting my FPScontroller to stick to the moving platform and have followed all above steps (collider, trigger, animation, allocating player tag in platform attach script). When I stand on the platform in the hierarchy the FPScontroller disappears as though it is child of platform parent, but it does not move it behaves just like at 4.30. I get this -- "ArgumentException: Object at index 0 is null". anyone got any clue/help/tips? thanks

  • @Zman2589
    @Zman2589 4 роки тому

    my player cant move it parents it and every thing but i lose control of player

  • @f.s5951
    @f.s5951 4 роки тому

    My Player Doesnt move with the ground although its attached

  • @manucamarixta
    @manucamarixta 4 роки тому

    It says Invalid expression term and unexpected character

  • @DrippyHonk
    @DrippyHonk 2 роки тому

    when I am going up and down my movement is very jittery and slow. Is there a fix for this?

  • @Mikelica69
    @Mikelica69 3 роки тому

    THANK YOU VERY MUCH!