解决了:
创建Node3D,SpringArm3D,Camera3D,结构下图
Node3D改名为focusNode
代码放在focusNode里
extends Node3D
var is_rotating = false
var sensitivity = 1
func _ready():
get_node("SpringArm3D").spring_length = 5
func _input(event):
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT:
if event.pressed:
is_rotating = true
else:
is_rotating = false
if event is InputEventMouseMotion and is_rotating:
var xRot = rotation.x - event.relative.y / 1000 * sensitivity
var yRot = rotation.y - event.relative.x / 1000 * sensitivity
rotation = Vector3(xRot,yRot,0)
if event is InputEventMouseButton:
if event.button_index == 5:
get_node("SpringArm3D").spring_length += 0.3
if event.button_index == 4:
get_node("SpringArm3D").spring_length -= 0.3
