Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

Pushed Into The Ground

Discussion in '2D' started by MoonJellyGames, Mar 5, 2015.

  1. MoonJellyGames

    MoonJellyGames

    Joined:
    Oct 2, 2014
    Posts:
    331
    I'm having a problem with my player being pushed slightly into the ground by objects that are on top of the player. I've posted here about this project several times, so maybe this will sound familiar, but basically this is how the game is supposed to work:

    You control a number of (currently that number is four) coloured smiley-faced box characters, one at a time. When you press the "C" key, the one you're controlling goes to sleep and the next one wakes up for you to control. You can stack players on top of each other and move them as a totem-like unit. I've tried *many* different things to make this work the way I need it to, and what I've got is very close.

    A single player can jump up and down without sinking into the ground at all. A stack that's two-high sinks an inconsequential amount. Three high sinks deep enough that you might notice some irregularities in movement in certain situations. Four high sinks enough to cause problems.

    After sinking into the ground, the player will get pushed back out if it changes directions. This seems to be thanks to the transform.x scale flip (from 1 to -1). This correction is fine for the moment as I can still make and test levels, it obviously doesn't solve the problem. Also, I'm probably going to need to axe that scale flip eventually because it messes with my joints.

    Anyways, I'm really hoping for some advice on making sure that the bottom player stops at the ground instead of sinking in slightly (as seen in the screen cap). I've read about and messed with the Physics and Physics2D settings and even the Time settings. Nothing seems to be able to keep the bottom player from being pushed into the ground by the players above it. Setting the "stacked" players' gravity scale to zero doesn't seem to have any effect and setting their mass to 0 (even on the condition that they are falling) is just disastrous.

    I was thinking there would be some way to use raycasts to detect the floor (something that already happens) and adjust something- even if just for a moment- that would prevent this from happening.

    Thanks in advanced. :)
     

    Attached Files:

  2. MoonJellyGames

    MoonJellyGames

    Joined:
    Oct 2, 2014
    Posts:
    331
    Bump.

    I had an idea, that is, to make the bottom (the "selected") player kinematic for a moment when he touches the ground, that way the force of the stacked players above him can't push him down, but I'm not sure how to implement this. Any ideas? Or alternatives?
     
  3. MoonJellyGames

    MoonJellyGames

    Joined:
    Oct 2, 2014
    Posts:
    331
    After much experimenting, I'm starting to think that it doesn't matter what the global physics settings are or what each player's properties are. It's a matter of which order collisions are being resolved in.

    The results of making a stack jump are inconsistent, but more often than not, the sinking problem happens. It's like upon landing, the bottom player's collision with the floor is resolved and then immediately after, the collision with the player above it is resolved, forcing the bottom player into the ground. Before the new ground collision is resolved, the third-from-the-top player collides with the second-from-the-top and so on. With all players shifted down slightly from their own player-to-player collisions, the bottom player can't get out of the ground because there is too much weight on top of it.

    That's the current thought anyways. :/ Don't you just wish Unity-God would come down, snap his fingers and make stuff work for you?