Saturday, December 15, 2012

Khan Academy Experiment–Absolute Values

I remember learning about absolute value equations in school. The only thing I retained was that they made V-shaped graphs and that was kind of cool, but I’m not sure I ever grasped an understanding of real-life situations where absolute values came into play.

So here’s an example (special thanks to Matthew DeLucas for suggesting the use case).  It’s extremely simple, but that’s okay because it’s supposed to be for Intro to Algebra stuff (it has some inequalities in there for good measure).  Note, it does not take into account the fact that the stage has bounds, so it’s still an oversimplified case.

You are making a 2D Fighting game (a la Street Fighter).  The part of the screen that is visible is 540 units wide, even though the stage is actually much wider, so you never want your players to be farther away from each other than the width of the visible screen (when players move the screen does not pan up and down, only left and right, so we only care about their positions on the x axis).  When the players get further away from each other than 540 units, the game should push them closer together.

If one player 1’s x position is 100, at what player 2 positions will the game need to push the players towards each other?

|x – 100| = 540

x = –440 or x = 640

image

image

Under what conditions will the game know that it needs to push the players together?

|Player1.x – Player2.x| > 540

|x-y| > 540

image

No comments: