0
votes

I have a physics body that is uneven but not dynamic (the terrain) and a physics body (character) that is dynamic and is on top of the terrain, and I want this character to move along the terrain simulating kind of a "walking" action where it will keep going up the terrain but it won't fall back (or move back) like a ball because of gravity, and to set a maximum tilt so that it does not tip over.

My attempt was to add a force in the direction I want the character to move but this is causing the character to fall back due to gravity, and I don't want to disable gravity because then character won't fall down when going down the terrain.

Thank you very much

2

2 Answers

0
votes

this is why using a physics engine for a platforming game is very difficult and not always a great approach..

you can try sprite.physicsBody.allowsRotation = false

might help

0
votes

Create SKAction to move your character to destination point or dx and dy. Run that SKAction from your character node with the runAction. Like SKAction.moveByX(...

When the action is finished, gravity will bring the character down.

If the movement is slow, play with the character's physicsBody friction and/or mass.

You can also change the the character's physicsBody.velocity = CGVectorMake(

And your terrain will be better with edgeLoop physicsBody which won't be dynamic.

And with uneven you mean inclined but smooth? If not smooth and with edges, your character may get held up at an edge depending on center of gravity of character and if you are allowing rotation.