5

My game has a Ferris Wheel with 4 seats. Each seat has a platform that the hero can rest on. When the seat is on the upward trajectory the hero calmly stays on the platform.

However, when the seat is on the downward trajectory the Hero moves up/down a bit.

I've tried a few obvious things: 1. Setting the restitution to 0 has no effect. 2. Setting linearDamping to 1 has no effect. 3. Making the mass of the platform and hero the same has no effect. 4. Adjusting friction has no effect.

Here is the platform physics body:

        supportNode?.physicsBody?.categoryBitMask = PhysicsCategory.ferrisPlatform.rawValue
        supportNode?.physicsBody?.mass = 1000
        supportNode?.physicsBody?.restitution = 0.0
        supportNode?.physicsBody?.friction = 0.0
        supportNode?.physicsBody?.linearDamping = 1.0

Here is the hero body:

    self.physicsBody?.linearDamping = 1.0
    self.physicsBody?.mass = 30
    self.physicsBody?.restitution = 0
    self.physicsBody?.friction = 0

Thanks for any tips. Its definitely bizarre that the hero is fine on the way up on the ferris wheel ride but only shows quirky up/down movement on the way down.

josh k
  • 268
  • 1
  • 11
  • I don't know an elegant answer for this, but I think it's just one of those things that goes wrong when you use a physics engine for platforming. You'll run into similar difficulties if you have a horizontally sliding platform that you want the player to stand on. Specifically, there are situations where you'd like the player to "stick" to a platform, but it's hard to describe that effect with the kinds of forces the engine wants you to use. – Aaron Golden Apr 25 '17 at 19:55
  • 1
    Take a look at this : http://stackoverflow.com/a/31594616 – Whirlwind Apr 25 '17 at 20:24
  • The seat is also suspended by a pin joint which may complicate matters further. So, its going up, down, and the angle changes. It seems like i need an approach to stick the the hero's y position to the seat platform's y position. – josh k Apr 25 '17 at 20:43
  • One idea, that seems insane, is attach the hero to the platform as a sliding joint. Hmmm. Thoughts on this approach? I'd have to be creating / destroying that joint as you enter / exit the seat. – josh k Apr 25 '17 at 21:37
  • 1
    One idea is to apply a constant downward force on the hero when it's position is such that you know it is on the down side of the wheel. – TheValyreanGroup Apr 25 '17 at 22:32
  • manually adjust the player's position in `didSimulatePhysics`. Set a contact delegate for the top of the platform... then set some value to `is on platform = true` then bypass the physics system to keep your hero in place. – Fluidity Apr 27 '17 at 01:54

3 Answers3

2

It seems like a problem of mass to me. The platform's mass has nothing to do with it because I read that it's pinned to the wheel. So you should increase the players's mass. If you go in a ferris wheel and make it spin fast enough, you will float too while going down. Setting restitution to 0 is good to avoid bounce, but it won't help keeping a light object in place: it's just not falling fast enough.

Also, you might want to actually increase the friction so the body won't slide. With 0 friction it's like sitting on ice.

BadgerBadger
  • 696
  • 3
  • 12
0

Manually adjust your player's position after physics calculations.. in didSimulatePhysics:

if player.isOnPlatform {

    player.position.y = platform.position.y // Maybe +1 or something like that

}

Now just add a contact delegate to toggle on / off when you make contact with the platform in didBegin(contact:

if player.position.y > platform.position.y { // So jumping under the platform wont warp you to the top
  player.isOnPlatform = true // Make sure to toggle this off at the right times as well, such as in you player.jump() method.
}

You will have to do the bitmasks etc and tweak it as other issues may come up, but this a good approach I think without affecting gravity / downward forces on player which will mess up the feel of the game when you are on a platform.

Fluidity
  • 3,985
  • 1
  • 13
  • 34
0

Setting the restitution to -1.0 on the hero and the platform solved this issue for me. This is in conflict with the documentation for restitution which says: "The property must be a value between 0.0 and 1.0"

josh k
  • 268
  • 1
  • 11