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...
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!
Thanks a lot
Thanks
thanks!
It works but I have an issue. If I have got the auto sync transform checked, it messes up my player movement. I don’t know why it does that
life saver
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
Thanks a lot
Thanks, great tip!
dude ur a genius
thx
Oh my god I love you.
THANKS YOU ARE GENIUS!!!!!!!
Thank you man honestly... you explained this in only 7 minutes like a pro. Keep it up :)
Thx will do... but hey: I AM a Pro:-)
@@JayAnAm don't push it, that's risky..
@@JayAnAm
Can you understand Arabic?
I want's describe my problem in Arabic.
@@ghadaghadoosh6496 No, sorry
@@JayAnAm
I want to be a planned paper on his paper and be wrapped then open this chart for a certain
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...
Hey, great it helped!
@@JayAnAm
It helped immensely. Thank you for the video man :)
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.
ok
thanks!
Bro how to fix shaking jittering effect when our player move with Moving platform
actually you can solve this with simple code:
player.transform.SetParent(movingObject, false); ---> "false" will disable resizing the player
worked!!! you the goat mane
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!
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
I have been stuck on this for so long and I am so grateful someone directed me to this video. Thank you so much!!!
Thanks brother , you saved my life, the script works perfect
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 👍
Yoo
your tutorials are lifesavers. thanks for being awesome
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!)
Thx, great you like it
@@JayAnAm glad*
OMG! I didn´t know that this is sooooo easy....
I love your videos, bro!
Glad you like them!
@@JayAnAm Can you help me? The Attach-BoxCollider doesn´t work... Thescript is correct, Is Trigger is true... I CAN´T FIND THE MISTAKE
omg tysm im making a vr game but im new to unity and after 2 days of being confused this video worked
that's what I was looking for THANK YOU SO MUCH !!
So great it helped!
@@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...
Thanks man I was not understanding why my script didn’t work I had to connect the player to the script super helpful
Thanks a lot that helped so much , really appreciated your short and super clear video , subscribed ^^' !
Cool, thank you
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
This worked perfectly even for going Up and Down. Thank you.
hey hiromu656, didn't think I'd see you here, just read you're newest update today. Can't wait for Thief's Roulette!
This works perfectly. Thanks, it's so simple and effective. Nice Joob, good video!
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
Ok
Which model
I am facing same problem maybu
Mayby
Is this working with 2020 version? Tried exactly what's shown in the code although the player doesn't move with the platform.
Edit: Nevermind, just put the animation to 'Always Animate.'
THANK YOU SO MUCH! you've made it so clear and easy!
Straightforwardly beautiful! Thank you!
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?
Me too, I move my player with the character controller.
here you can watch jimmy vegas unparent the platform tutorial ua-cam.com/video/Ni1YOa8AaLg/v-deo.html
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
Really useful - solved my elevator 'problem' :)
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
The Platform is not moving in Play Mode but it is running well in Animation Mode
I have this same issue
when doing this my object stretches? anyone got a similar problem?
Welcome to the club! My sphere gets stretched out. I will present this as a feature, not a bug.
Same
@@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)
GG Entertainment I’ll try that, thanks for the suggestion.
yes I had the same problem use a platform without scale
This helped me a lot
Hey that's great
@@JayAnAm 👍
Some I greatly need without coding for the platform's animation
it kinda works. but player slides so doesnt move with platform completely. not using animator. moving block with its own script moving its vector.
Awesome! Workd like a charm!
Great to hear!
It is not working for me. My character that uses CharacterController does not stick with the platform.
It parents the player to the platform, but still just slides off.
I have that same issue
@@yetilee were you able to resolve the issue?
@@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.
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
Yay! This worked for me, thanks so much.
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?
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
Thank you bro works like a charm
THANK YOU FOR CREATING THIS VIDEO! BECAUSE I HAVE THIS PROBLEM!
Perfect and simple. Thank you
Omg Thank you I have been trying to get this to work for about 20 min until I found your video THANKYOU
could you do a video that does this but with a force with a rigid body?
Damn this is a good tutorial. So simple!
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
Thank you so much for this awesome tutorial
oh very very very thank you sooo much brother. you really helped me.
its sooooo good ! thanks dude
Help please my player size als changes when I get onto the platform
I have the same problem :c
@@akiorsgames me 2
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.
did you find a fix?
Is there a fix for that? I really need it
amazingly explained mate.
thanks this was great
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...
any luck on fixing that? same here....
Is there a way to add serialized player list to recognise more than one player jumping on the platform?
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?
answers.unity.com/questions/898093/the-scale-of-my-object-after-parenting-to-a-moving.html
Tricky Akshay, Thank you so much!
Assets\Scripts\PlatformAttach.cs(15,39): error CS0103: The name 'tranform' does not exist in the current context
How to make it for the Enemy and Player both at same floating cube??
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?
Thanks a lot
You are very welcome
my player didnt stick to the plataform, i have used a first person player
rully great idea
you are my savior
Haha.. thx
Great video, thank you! All works fine accept can't jump off platform, only walk - could this be a box collider issue?
Thanks dude, big help!
i got an problem called expected but can't seem to find it :|
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.
I have the same problem. The player is dynamically moved under the platform in the hierarchy but it is not moving with it.
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.
Great it works for me, thank you so much!!!!
great tutorial
does this work for ships?? and what about if there is more than 1 player?
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
Life saver, thank you :)
i wonder if it still works with no new input system
This is solution only works if the platform you are parenting player under has X and Z rotation on 0 and static Y position.
Thanks you so much It's realy hepful !! :)
Great it helps!
Very nice video!
Thank you now my player is moving with platform but it will change the player size what shouldi do to fix it???
hey friend I have a problem and that is when the character collides with the platform deforms the player pd is a rollerball standartassets
oh men me too, it's weird, any solution?
@@sumbanananitro Have you checked to see if the platform's collider is set to "Is Trigger"?
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.
Dont work with fps controller and unity 2018.3 ?
Same problem with unity 2018.4
ua-cam.com/video/wwxdqdSbYds/v-deo.html
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?
absolutely AMAZING!!!!!!!!!!!!!!!!!!
can you send me link to the script? m yvisual studio is not working so i need to download it pls
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
this doesnt work with physics because the rigidbody overrides the new position. how do you make one that works with physics?
what If the platform move vertically?
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?
When I jump off of the platform it deletes the platform altogether. Does anybody know why and how to fix it?
My player gets attached to the platform but can't move while on it does someone know how to solve this?
Try this one ua-cam.com/video/wwxdqdSbYds/v-deo.html
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?
Facing the same problem...did you find any solution??
thank you so much !!
you great !!!
Thank you!!
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?
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?
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
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)
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
my player cant move it parents it and every thing but i lose control of player
My Player Doesnt move with the ground although its attached
It says Invalid expression term and unexpected character
when I am going up and down my movement is very jittery and slow. Is there a fix for this?
THANK YOU VERY MUCH!