Posts

Showing posts with the label physics

Give the player some friction when moving after being pushed

Image
Give the player some friction when moving after being pushed Not really sure how to word this but lets say you are a ball and are bouncing around and moving. Its a flat surface so everything moves fine. Now introduce some 45 degree ramps. You fall on one straight down and bounce away from it. At the moment you can instantly move back regardless of how soon you hit it or what angle or speed your traveling at where it should be harder from the momentum of the push because it was at an angle. Kind of like a small gradual momentum until you reach 0 velocity, then you can move normally. if (playerLeft) { float xVelocity = (playerBody.velocity.x > 0) ? playerBody.velocity.x - playerSpeed : -playerSpeed; playerBody.velocity = new Vector3(xVelocity, playerBody.velocity.y, 0); } if (playerRight) { float xVelocity = (playerBody.velocity.x < 0) ? playerBody.velocity.x + playerSpeed : playerSpeed; playerBody.velocity = new Vector3(xVelocity...