Which camera is suitable for 2.5D

Hey there!

I was making a 2.5D top down style shooter game (graphics are in 3D), and wanted to use the FollowCamera (Which is amazing!). But the problem I am encountering is that the camera rotates as the mesh rotates, which is not what I want. I went out trying UniversalCamera and ArcRotateCamera but the movement of it when following the mesh is jittery. I’m not sure whether 1) I am implementing the follow movement of UC and ARC in the wrong way, 2) is there an option to disable the FollowCamera from turning due to the mesh, 3) is there an alternate camera for this use? . Could someone help me here? I’m new to BJS, so I don’t have much experience.

Thanks a lot to reading through! Thanks in advance!

you could try mesh.position.add(new BABYLON.Vector3(0, 10, 0));
This acts like parenting but without the rotation. You’ll have to call it every frame, though, so

scene.registerBeforeRender(function() { 
   mesh.position.add(new BABYLON.Vector3(0, 10, 0)); 
});

@Givo But I am moving my mesh by mesh.moveWithCollisions()…

That shouldn’t have any effects on it. Or does it?

I don’t think it should because I’ve been using mesh.position.add with a mesh that has physics and it doesn’t change anything. It’s like parenting, except the child mesh doesn’t inherit the parent’s rotation.

@Givo I’m not clear on what you’re saying, maybe a playground should remove the fog? Would appreciate that!

Yeah, a playground would be very helpful.

@ADIGEN How’s the PG coming? (sorry if I’m being pushy)

@Givo Oh no I’m sorry for the miss understanding, I thought you would try to show an example in a pg! Anyways, I tried it out, not able to figure out what exactly you meant by .add…

(I’m very sorry)

Oh it’s fine. I thought you had all of the top-down movement controls already. I can make a pg real quick.

15 minutes later: @ADIGEN Here is an example: https://playground.babylonjs.com/#15EY4F#31 WASD or arrow keys to move around, q and e to rotate the sphere. Let me know what you think!

1 Like

https://playground.babylonjs.com/#X2FVF5#3

Ignore the scene but the controls work.

-+ to Zoom, arrows to move.

Wow thanks a lot @Givo ! I misunderstood the way I should use mesh.position.add (thought that I should trigger that whenever I press a movement key :joy: ). I had the controls ready, I just didn’t understand what you meant. I went through the docs, it said .add is used for adding two vectors. I thought you meant me to use it to move the mesh!

Hmm so now I have found the answer, just for curiosity, isn’t the .add method gonna do the same thing as equating (is it the right term I’m using?) the player/sphere position with the camera position?, cause when I do it manually, I see the jitter…

Thanks a lot! Gratitude to @Pryme8 too!

Oh, it’s fine. I really didn’t explain it all that well. By the eqating, do you mean that it would make the player’s position the same as the camera’s? And when you do camera.position = new BABYLON.Vector3(player.position.x, player.position.y + 10, player.position.z); the camera jitters?

You tried parenting the camera to the player, right? Did it jitter then?

Yes @Givo , it does jitter, I mean, I did this exactly:
camera.position.x = player.position.x; camera.position.y = player.position.y + 10 camera.position.z = player.position.z + 2 Which makes really no difference than defining a new vector, Or does it?

Uhm no I didn’t try parenting the camera, did you mean
camera.parent = player;?

EDIT: Let me try out everything you mentioned, please give me some time!

EDIT (2): Yes @Givo , it does jitter by the above method you mentioned, plus parenting it makes the player’s rotation affect the camera :frowning_face:.

yes. The only problem with that is that the camera will rotated with the player. Not a long-term solution, but just to see if it jitters.

EDIT: I just saw your edit.

Anyways, the .add method is working perfectly! Just had to ask whether we are allowed to talk in such a way on a post (with around 15 replies), or should we talk in a private message…just had a concern about that.

Oh, ok. Glad it works and can’t wait to see the game!

1 Like

something like this might help with jitter

camera.position = BABYLON.Vector3.Lerp(newPosition, currentPosition, 0.8)

Thanks @Pryme8! Will test it out!