Hey there!
So I’ve been working on figuring out how to make a 2d platformer and I’ve gotten a bit stuck. I’m attempting to make a platform that moves up and down. While on the moving platform my character tends to bounce on the way up and then settle down on the way down.
Here’s what I’ve got setup so far:
- The main character has a
RigidBody2D
set to dynamic and aBox Collider 2D
on it - The platform has a
RigidBody2D
set to kinematic and aBox Collider 2D
on it
The player script utilizes velocity
-based movement in the x
direction and to retain the RigidBody
’s y
velocity.
The platform uses velocity to move in a particular direction calculated by the next point to move to in a set of points on screen and the current one (so I want to move to the second point from the first then it’s second - first to get the direction).
On my movement script on the player, I have the OnCollisionEnter2D
and OnCollisionExit2D
methods in place. Upon collision entering, I set the parent of the player to the platform. When it exits I set the parent to null
. This is, by what I’ve seen on the internet, the preferred way of doing things. However I get this bounce when I do it.
There’s a couple oddities / experiments I’ve got going on here that might help shed some light as well:
- In order to get horizontal platforms moving, previous to this, I had to keep a reference to the platform’s rigid body so I could add the velocity of that to my movement so the player would move with the horizontal platform. I suspect this is not helping with the bounce. On the flip side, when I stop using the reference to the platform’s velocity, the player moves up and down the platform smoothly but when it hits the top of the vertical movement it bounces into the air (it gets real intense on speedier platforms).
- I tried overcoming the general falling that I believed was going on by setting the gravity of the player’s rigid body to a high number… This technically works for the platforms at the speed they move now but not faster.
Any help would be very helpful. If you need direct code snippets let me know and I can add those.
Using Unity 2022.3.11f1 silicon