msmshazan Shazan Shums 169 posts Some day I will make quality software.Programming FTW. 2d physics using rays 2 years, 5 months ago Hi I'm trying to implement sonic like engine . currently using aabb and was thinking how to implement ledge animations using rays. But I'm stuck in implementation. Just being curious on programming....
 AsafG Asaf Gartner 37 posts Handmade Network Staff 2d physics using rays 2 years, 5 months ago You mean Sonic the Hedgehog? This is a pretty interesting guide: http://info.sonicretro.org/Sonic_Physics_Guide The solid tiles section talks about slopes and ledges.
 msmshazan Shazan Shums 169 posts Some day I will make quality software.Programming FTW. 2d physics using rays 2 years, 5 months ago In platformers should movement be force based or impulse based and I am using velocity verlet integrator will this effect movement at this situation? Just being curious on programming....
2d physics using rays
2 years, 5 months ago

I would just do it by only keeping track of velocity (and of course the previous frame's velocity as is required for velocity-verlet integration). Force or impulse based simulation is overkill for most platformers IMO, but it depends on what you want to do of course. For example, Sonic for example does it in the same kind of way as I will describe here, but something radically different like Grow Home uses a full force and impulse based physics simulation for it's movement.
Anyway, here's how I'd do it:
Every frame you add the gravity to the velocity like this:
 `1` ```velocity.y += gravity * deltaTime ```
.
The horizontal movement can be done by simply lerping the X component of the velocity vector to the input like this:
 `1` ```velocity.x = lerp(velocity.x, movementSpeed * inputX, movementAcceleration * deltaTime) ```

(This is just one way of doing horizontal movement, you could also do it with acceleration and drag instead of lerp, but I find that harder to tweak.)
When you want to jump, just set the Y component of the velocity like this:
 `1` ```velocity.y = jumpVelocity ```

At the end of the frame you'd just integrate the velocity (via velocity-verlet) and add it to the position. (Of course you'd do raycasting before applying the velocity first though, so you know how much you can move without colliding)