How can I get the physical body of a hero so that I can relax on the physical body of a moving platform?

My game has a Ferris wheel with 4 seats. Each place has a platform on which the hero can lean. When the seat is on an upward trajectory, the hero remains calmly on the platform.

However, when the seat is on a downward path, the Hero moves up / down a little.

I tried a few obvious things: 1. Setting restitution to 0 does not affect. 2. Setting linearDamping to 1 has no effect. 3. Creating the mass of the platform and the hero has no effect. 4. Friction adjustment is not affected.

Here is the body of the physics platform:

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’s body:

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

Thanks for any advice. Its definitely weird that the hero is great for riding a ferry wheel, but only shows a fancy up / down movement down the road.

+5
source share
3 answers

This seems to be a mass problem for me. The mass of the platform has nothing to do with it, because I read that he pinned to the steering wheel. Thus, you must increase the mass of players. If you go into the Ferris wheel and make it spin fast enough, you will also swim when you go down. Setting the restitution to 0 is good to avoid failures, but it will not help keep the lightweight object in place: it just does not fall fast enough.

In addition, you may need to increase friction so that the body does not slip. With 0 friction, he sits on ice.

+2
source

Manually adjust your player’s position after physical calculations .. in didSimulatePhysics :

 if player.isOnPlatform { player.position.y = platform.position.y // Maybe +1 or something like that } 

Now just add the contact delegate to enable / disable when you didBegin(contact in touch 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 bitmasks, etc. and customize them, as other problems may arise, but this is a good approach, I think, without affecting the gravity / downward movement on the player, which will ruin the feeling of the game when you are on the platform.

0
source

Setting the restitution to -1.0 for the hero, and the platform solved this problem for me. This contradicts the documentation for restitution, which states: "The property must be a value from 0.0 to 1.0"

0
source

Source: https://habr.com/ru/post/1267155/


All Articles