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
, connectX
coordinate from Separate XYZ intoA
socket, andFloat
output socket from camera distance intoB
socket. This will get player’sX
position (horizontal) and set camera’sX
position accordingly.Add another Math node under the first one, connect
Z
coordinate from Separate XYZ intoA
socket, and setB
value to1.0
.Add Combine XYZ node, connect top Math node into
X
, bottom Math node intoZ
, andY
socket from Separate XYZ directly intoY
socket.Above first Math node, add Active Camera, next another Get World Position above Combine XYZ, and connect
Camera
as Object.Next add Vector Math node, set ‘Operation’ to
Add
, connect Get World Position into topVector 1
socket, Combine XYZ intoVector 2
socket.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
Condition
socket, Active Camera as Object, and last Vector Math intoValue
socket.With ‘player’ selected,
.
Done.