Slopey McSlopeface (part 2)

posted in The Berg for project The Berg
Published October 06, 2018
Advertisement

Having played around with the character movement a bit more I realised I was doing many things wrong.  Not that I had ever intended to do things perfectly, but the slope handling just wasn't up to scratch.  I had acceleration working, but deceleration didn't due to the way I had built things.  So I decided to do a little bit of an overhaul of the player movement system.  Nothing too major it turns out but I now have both acceleration and deceleration working very nicely and it gives a much smoother feel to the controls.  It's subtle but necessary in my opinion.

There is one aspect of slopes that I haven't tackled yet though and that is falling, tumbling or sliding on steep slopes.  As I'm not using any fancy physics engine my player character is essentially glued to the terrain like it's on rails.  It's not really an issue in so far as jumping is concerned because I don't intend to have any jumping ability in the game.  However, I decided that I didn't want to artificially prevent the player from walking off the edge of a cliff so I need some form of falling action (and tumbling if you run down a steep slope too fast - potentially injuring yourself).

So what I've done is add forces into my CollisionBody class to represent an accelerant force due to gravity.  But to keep my brain from imploding over the quirks of simulating physics (and so as not to have to implement a full-blown physics engine) I decided to half keep the on-rails aspect by doing this:


if ( obj.collisionBody.position.y <= targetPos.y ) {
    obj.collisionBody.position.y = targetPos.y;
    obj.collisionBody.resetForces();
} else {
    // Apply gravity
    obj.collisionBody.applyForce( new Force( DEFAULT_VECTORS.down, _this.gAcceleration ) );
}

Where 'targetPos' is the ground position.  So if the player is in contact with the ground or moves below it, then they player will just snap back to the precise point on the terrain.  It's only when the player goes above the terrain (into the air) that gravity comes into play.  This helps keep things nice and simple and gives a nice feel to the movement.

Oh and I've also added in some 'head-bobbing' to add a bit of realism to the movement.  Overall it gives a really nice result.... and I can now fall off cliffs...

You may also notice that the camera rotation is now much smoother too as I now 'slerp' between rotations rather than doing absolute movements, although my screen recording software doesn't do it justice in the video above.

1 likes 0 comments

Comments

Awoken

This looks very good.  

October 06, 2018 02:10 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement
Advertisement