Wednesday, May 30, 2012

Bounciness Fixed, Now Quick Sand


I fixed the bounciness by adding a state variable called impact that is true when the player makes contact with a block. When impact is true, the magnitude of the contact force is equal to:

mass * velocity.magProj(new Vector(nTheta + Math.PI, 1)) / dt

In my bouncy build it was mass * velocity.magProj(new Vector(velocity.getTheta() + Math.PI, 1)) / dt which is wrong. I don't know what I was thinking.

When impact is false the magnitude of the contact force is equal to:

sumForce.magProj(new Vector(nTheta + Math.PI, 1)

The reason the player sinks is not exactly clear to me. After the impact force is applied to the player, he bounces up for about 2 frames then lands again and gets another (but smaller) impact force. After this, f_net in the y direction is zero. The problem is that there is some left over velocity (on the order of 2 pixels per frame) from the impact. It looks like the impact force is slightly too small. Maybe? I'm not sure.

In this video, the player is shot off the screen as if from a cannon because it is getting the normal forces from the sides of the blocks. This should be fixed when I fix the sinking.

The sinking isn't just in the Y direction. It happens on the walls too. I'll figure this out soon...

So. Much. Physics. Maybe classical Newtonian physics was a bad idea but now I'm stuck with it. Hopefully it pays off in the end.

I've finished my exams so I think I'll be up most of tonight coding.

No comments:

Post a Comment