+1 vote

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():


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

func _ready():

    character = get_node(".")

func _physics_process(delta):
    camera = get_node("CameraBase/Camera").get_global_transform().basis
    var dir = Vector3()
    var is_moving = false

        dir += -camera[2]
        is_moving = true
        #gimbal.translation.z = character.translation.z
        dir += camera[2]
        is_moving = true
        dir += -camera[0]
        is_moving = true
        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

Thanks for your help :D

in Engine by (20 points)

3 Answers

0 votes
Best answer

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

just add set_as_top_level(true) on camera

by (20 points)
0 votes

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

if you still will going with WASD you can change:

dir += Vecor3(1,0,0)
moving = true

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

by (32 points)

When remove lookatfrom_position
when remove camera script

and I already follow your movement script, but still

0 votes

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 . . :D :D

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

by (99 points)

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.