1. Camera Movement
In 2d scroller games, camera is usually showing player from the side, and it moves perpendicularly together with the player. If you press Numpad 0 (zero - camera perspective), or Numpad 3, you should see player from same perspective (press Numpad , (comma) to focus the player).
Add a new logic tree, name it ‘player_2d_camera’, and set ‘Fake User’.
Next add, from left to right, Get World Position, set ‘player’ as Object - it will get player’s position, so camera knows where to go, following the player.
Add Separate XYZ vector node, to separate 3D vector into separate XYZ coordinates from ‘World Position’; connect the sockets.
Under above node, add 2 Float nodes - one will set camera distance from player, the other will set following speed. Select both ‘Float’ nodes, hit Ctrl-J - this will group both nodes into a frame, for better organization. Rename top node to ‘camera distance’, and set value to i.e.
30.0; rename bottom one to ‘slow camera’, set value to i.e.0.15(with node selected - side ). Also, with frame selected, rename it i.e. into ‘camera custom’, and also change frame color (below ‘Label’).Next add Math node, set operation to
Add, connectXcoordinate from Separate XYZ intoAsocket, andFloatoutput socket from camera distance intoBsocket. This will get player’sXposition (horizontal) and set camera’sXposition accordingly.Add another Math node under the first one, connect
Zcoordinate from Separate XYZ intoAsocket, and setBvalue to1.0.Add Combine XYZ node, connect top Math node into
X, bottom Math node intoZ, andYsocket from Separate XYZ directly intoYsocket.Above first Math node, add Active Camera, next another Get World Position above Combine XYZ, and connect
Cameraas Object.Next add Vector Math node, set ‘Operation’ to
Add, connect Get World Position into topVector 1socket, Combine XYZ intoVector 2socket.Next add another Vector Math, set ‘Operation’ to
Scale, connect previous node intoVector 1, and slow follow intoScale.Add On Update above last node, next Set World Position node; connect On Update into
Conditionsocket, Active Camera as Object, and last Vector Math intoValuesocket.With ‘player’ selected, .
Done.
2D player camera nodes setup