How to setup camera for 3D game

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By StarX1709

Hello!
I am working on a 3D TPS shooting games where my player needs a camera to follow. This is my code note.

func _unhandled_input(event): # This function for mouse direction 
	if event is InputEventMouseMotion:
		
		rotate_y(-lerp(0,spin,event.relative.x/20))#Spin=0.2
func _physics_process(delta):

However this code only works in horizontal way means i can see and move only in left right direction. Now i want to know how see Up and down(like seeing a tall building just seeing not moving our charcter)in camera through mouse motion.

:bust_in_silhouette: Reply From: Wakatta

Not sure which direction your axis’s are pointing so you’ll have to adjust rotate_xyz() accordingly a direct answer to your question would be

func _unhandled_input(event): # This function for mouse direction 
    if event is InputEventMouseMotion:

        rotate_z(-lerp(0,spin,event.relative.x/20))#Spin=0.2
        rotate_x(-lerp(0,spin,event.relative.y/20))
func _physics_process(delta):

That should work however may create another problem, so recommend locking mouse to the window

func _ready():
    Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)

Set the camera to be the child of a spatial and manipulate the transforms of that instead

Thanks! for your suggestion but i have already used this technique except that capturing code. But it still did not worked.
But again thanks for suggestion.

StarX1709 | 2020-08-31 07:20

Hey!
i found the solution here is my new code for vertical view

func _unhandled_input(event): # This function is  for mouse direction 
if event is InputEventMouseMotion:
	cam_rotate.rotate_x(-lerp(0,spin,event.relative.y/100)) # This is for the vertical mouse motion
	rotate_y(-lerp(0,spin,event.relative.x/20)) # This is for the horizontal mouse motion 
	#cam_rotate-> onready var cam_rotate = get_node("camera")

If anyone have more suggestion i will be thankful to him.

StarX1709 | 2020-08-31 07:59