0
\$\begingroup\$

I'm working on 2D top down zombie game. I started working on it as having a static 2D map and on every tick you update the coordinates of every object, including the player itself relative to the static map. Every object has x, y and angle against x axis x, y, theta.

But I would like to also provide a way to see it as a kinda third-person shooter (still top down 2d just different center of coordinates), where camera and coordinates are connected to the moving player object. So the player would always have the 0, 0, 0 coordinates and every other object transformed xT, yT, thetaT coordinates.

enter image description here

What approach should be used in such cases? Should I still keep the static coordinates and simulate the world over a static map, and then transform the coordinates of every object into relative coordinates? So every tick there will be two transformations - world simulation and static -> relative coordinate transformation?

\$\endgroup\$
3
  • \$\begingroup\$ Just to be clear, are you talking about a 3D first-person view or merely a top-down view that follows the player? \$\endgroup\$
    – Quentin
    Commented Dec 27, 2018 at 9:13
  • \$\begingroup\$ Same top down, just different coordinates, yes top down that follows the player \$\endgroup\$
    – Alex Craft
    Commented Dec 27, 2018 at 10:04
  • 1
    \$\begingroup\$ Note that "first person" means you're looking through the character's eyes. If you can see the top/back of the character's head, then you're not in first-person view, but rather third-person. What you're describing is a top-down follow cam, not first-person view, and I recommend adjusting the terminology in your question to match. \$\endgroup\$
    – DMGregory
    Commented Dec 27, 2018 at 17:39

1 Answer 1

1
\$\begingroup\$

You should keep everything in the static world frame and only transform them into the player's coordinate frame when necessary. This will reduce many headaches along the way because your static reference frame will be independent of the player's position and velocity.

That makes it possible to reference objects w.r.t fixed coordinates or regions in the level which never have to be changed. For example "is this monster inside this door?" becomes a simple box vs. box check and requires no reference frame transformation. It also allows you to cache the coordinates of every non-moving object.

As for "transforming into the player's reference frame every tick," yes, you do this but not on the CPU. Just set up your game's rendering system to appropriately adjust the World and View matrices so that the GPU takes care of that for you at draw time. The standard pratice would be to set up an orthographic perspective matrix and a view matrix centered on your player.

Aside from that, there are a few times you'll want to transform coordinates into the player's reference frame -- but I suspect they're fewer than you anticipate. It won't have to be for every object, and it certainly won't have to be for every tick.

\$\endgroup\$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .