Camera Following without player rotation

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

Hello, I’m new in Godot. I’ve been following this tutorial for my game. but, in this tutorial, the camera is following the rotation of the character. I want to make the camera following like a bird view or an isometric platform game, like Torchlight 2 or Diablo
Torchlight 2 Camera

The script for camera following is

extends Camera

export var distance = 4.0
export var height = 2.0

func _ready():
	
	set_physics_process(true)
	set_as_toplevel(true)
	
func _physics_process(delta):
	var target = get_parent().get_global_transform().origin
	var pos = get_global_transform().origin
	var up = Vector3(0,1,0)
	
	var offset = pos - target
	
	offset = offset.normalized()*distance
	offset.y = height
	
	pos = target + offset
	
	look_at_from_position(pos, target, up)

and attached script for player movement is

extends KinematicBody


var gravity = -9.8
var velocity = Vector3()
var camera
var character

const SPEED = 6
const ACCELERATION = 3
const DE_ACCELERATION = 2

func _ready():
	#pass 
	
	
	character = get_node(".")
	
	
func _physics_process(delta):
	camera = get_node("CameraBase/Camera").get_global_transform().basis
	var dir = Vector3()
	var is_moving = false
	
	if(Input.is_action_pressed("move_fw")):
		dir += -camera[2]
		is_moving = true
		#gimbal.translation.z = character.translation.z
	if(Input.is_action_pressed("move_bw")):
		dir += camera[2]
		is_moving = true
	if(Input.is_action_pressed("move_l")):
		dir += -camera[0]
		is_moving = true
	if(Input.is_action_pressed("move_r")):
		dir += camera[0]
		is_moving = true
		
	dir.y = 0
	dir = dir.normalized()
	
	velocity.y += delta * gravity
	
	var hv = velocity
	hv.y = 0 
	
	var new_pos = dir * SPEED
	var accel = DE_ACCELERATION
	
	if (dir.dot(hv)>0):
		accel = ACCELERATION
	
	hv = hv.linear_interpolate(new_pos, accel * delta)
	velocity.x = hv.x
	velocity.z = hv.z
	
	velocity = move_and_slide(velocity, Vector3(0,1,0))
	
	if is_moving:
		var angle = atan2(hv.x, hv.z)
		
		var char_rot = character.get_rotation()
		
		char_rot.y = angle
		character.set_rotation(char_rot)

Thanks for your help :smiley:

:bust_in_silhouette: Reply From: TheLoraxPl

In character scene you can set location of camera to isometric
Remove camera script or comment line: look_at_from_position(pos, target, up)

if you still will going with WASD you can change:

if(Input.is_action_pressed(“move_fw”)):
dir += Vecor3(1,0,0)
is_moving = true

… dir += Vecor3(-1,0,0)
… dir += Vecor3(0,0,1)
… dir += Vecor3(0,0,-1)

When remove look_at_from_position
when remove camera script

and I already follow your movement script, but still

vockerz | 2020-05-12 14:58

:bust_in_silhouette: Reply From: jasperbrooks79

I sort of just SET-position camera, in camera script to GET-player-position + camera-offset, every frame, so the camera follows, but doesn’t rotate . . :smiley: :smiley:

You can also add the code, in the character node, same thing, easy, using visual script <3 <3

yeah i know its actually simple logic like this, but i still try to understand this GDscript. I wanna try visual script, can u drop a link for visual script tutorial?

thanks man

vockerz | 2020-05-11 22:55

:bust_in_silhouette: Reply From: vockerz

solved in this video : https://www.youtube.com/watch?v=V09nHX_cKjI

just add set_as_top_level(true) on camera