- Home /
Design/discussion question
Moving platform and friction problem
Hey all. I know there's a ton of moving platform questions, and I have read just about all of the questions/answers that came up in my "moving platform" search. None of the proposed solutions have worked for my 2D platformer, and it's probably because my moving platforms can also become controllable characters.
In my game, there are at least three characters that the player can control, using a button to cycle between them. All of the characters are (0.34,0.39) in size-- nearly square. They're small because the original sprites were only 16x17 px and I have not yet adjusted the scale. This is the behaviour I'm shooting for:
Selected character
The selected character is under direct control of the player. You can move left and right, and jump. That's pretty much it.
The player needs to be able to jump against walls without sticking to them. The way that I've decided to handle this is by attaching a PhysicsMaterial2D to my "Player" with zero friction. This is likely part of my problem, but I couldn't find a better solution.
The selected character should be able to walk and jump on any !selected player. I'm using a transform object to detect the layer of objects beneath my player. It will constantly return "true" if the "Player" layer is a part of the layer mask, so I unchecked that layer. Of course, then you can't walk/jump on other players. To get around this, I created two separate layers: "SelectedPlayer" and "NotSelectedPlayer".
The selected character should not be weighed down by character stacked on top of it. I expect that this will require some conditional adjustment of either the top characters' mass or the selected character's maximum x-velocity.
Not selected player
Should not be pushable by the selected character if the selected character bumps into it.
If on top of another character (it doesn't matter if the bottom character is selected or not), the !selected character should ride the bottom player, maintaining its x-position relative to the bottom character.
If the selected character walks through a tunnel that isn't high enough for the riding character to get through, the riding character should be peeled off.
Something that might solve part of the problem is if I could get the velocity of the bottom character with a raycast or something, and set the x-velocity of the top player (provided that it is !selected) to the x-velocity of the bottom player in the Update function.
I hope I've explained that well enough. I'm new to Unity, but I feel like I'm getting the hang of it, despite the frequent bumps I've encountered. If anybody has some suggestions, I would greatly appreciate it. And please ask if you need more detail.
Answer by robertbu · Oct 06, 2014 at 12:26 AM
I see the answers to this question being a discussion rather than a single specific answer. We ask that design questions be posted to Unity Forums. If you do post on the forums, I suggest you add a comment with a link from here to the forum question. That way anyone wanting to follow or participate in the discussion can find your forum question.
Ah, alright. Sorry about that. I've created a thread in the "2D" forum section, here: http://forum.unity3d.com/threads/unique-moving-platform-problem.272419/
No reason to be sorry. And after you get your general design questions answered, we'll be here for your specific questions.