0
\$\begingroup\$

I generate a 3d isometric terrain with the help of badlogicgames. I pass a perspective camera to the spriteBatch projectionMatrix, but when I move my player (perspective camera follows my player) it seems like the terrain is moving - here's some video of my game. I think the terrain should be static. I am also using decalBatch; my decals look fine - they remain in their position instead, the terrain does not.

This is part of the code where I render terrain:

sb.setTransformMatrix(matrix);
sb.setProjectionMatrix(cam.combined);//is perspective
sb.begin();
for(int z = 0; z < 100; z++) {
    for(int x = 0; x <80; x++) {
        sprites[x][z].draw(sb);
    }
}
sb.end()

here is the third person camera

cam.lookAt(player.getX(), 0, player.getZ());

cam.position.set(player.getX(),7f,player.getZ()-10f);

playerDecal.setPosition(player.getX(), player.getY(), player.getZ());

The problem is that terrain keeps moving around along with my camera's position. Does anybody have a clue?

\$\endgroup\$
  • \$\begingroup\$ check if the matrix ( setTransformMatrix(matrix) ) is correct. \$\endgroup\$ – Sidar Sep 29 '17 at 9:34
  • \$\begingroup\$ It's not clear to me from the video what artifact you're trying to correct. It looks like you're able to walk around your level in a sensible way — as your character moves right, the camera follows them so they stay centered on the screen, and the environment scrolls leftward by what looks like a reasonable corresponding amount for your character's movement. Can you annotate it in sone way to clarify what the symptoms of the problem are? \$\endgroup\$ – DMGregory Sep 29 '17 at 12:20
  • \$\begingroup\$ @DMGregory If you look at the plane and quads facing the camera you can see that the ground shifts in a way that the quads appear as if they are floating. Like the trees and bushes aren't rooted. Was hard for me to spot at first as well. \$\endgroup\$ – Sidar Sep 30 '17 at 9:49
1
\$\begingroup\$

Why are you setting the transform matrix? cam.combined is already transformed. It's a combined projection/transformation matrix.

Try add this line at the top

matrix.idt();

If that fixes it, then just delete the top line of your code, you don't need to set it unless it's been set somewhere else.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.