How to translate the camera around an Object while looking at it?

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

I want that, when I press m the camera to move around an Object but to keep looking at it.
Here are som pics: Imgur: The magic of the Internet


extends KinematicBody

export var moveSpeed : float = 5.0
var vel : Vector3 = Vector3()

onready var camera = get_node("CameraOrbit")
onready var kaijuNodeAnim = get_node("CameraOrbit/Kaiju_Model_Anim2").get_node("AnimationPlayer")
onready var kaijuNodeModel = get_node("CameraOrbit/Kaiju_Model_Anim2")
onready var cameraOrbitNodeCamera = get_node("CameraOrbit").get_node("Camera")

func _physics_process(delta):
	vel.x = 0
	vel.x = 0
	var input = Vector3()
	if Input.is_action_pressed("ui_up"):
		input.x += 1"Walk")
	elif Input.is_action_pressed("ui_down"):
		input.x -= 1"Walk")
	elif Input.is_action_pressed("ui_right"):
		input.z += 1"Walk")
	elif Input.is_action_pressed("ui_left"):
		input.z -= 1"Walk")
	elif Input.is_action_pressed("ui_m"):"Dance")
		cameraOrbitNodeCamera.translate(Vector3(cos(OS.get_ticks_msec()*0.01) * PI, 0, sin(OS.get_ticks_msec()*0.01)*PI))
	input = input.normalized()
	var dir = (transform.basis.z * input.z + transform.basis.x * input.x)
	vel.x = dir.x * moveSpeed
	vel.z = dir.z * moveSpeed
	vel = move_and_slide(vel, Vector3.UP)
:bust_in_silhouette: Reply From: ramazan

var target = $target_object

$Camera.look_at(target.get_global_transform().origin, Vector3.UP)

Thanks! Works good. Now, for extra kudos, how can I make it that when I stop pressing “m” it returns to its original position?

animanoir | 2022-02-02 09:21


var first_pos = null

func _ready():
    first_pos = cameraOrbitNodeCamera.global_transform.origin
    // first_pos = cameraOrbitNodeCamera.transform.origin


    cameraOrbitNodeCamera.transform.origin = first_pos

ramazan | 2022-02-02 09:33