Added some camera control by holding down middle mouse button.
This commit is contained in:
parent
8feb7bbc47
commit
0e03ced3c6
@ -7,6 +7,10 @@ const MOVE_SPEED := 8.0
|
|||||||
const ACCELLERATION := 30.0
|
const ACCELLERATION := 30.0
|
||||||
const DECELLERATION := 40.0
|
const DECELLERATION := 40.0
|
||||||
const JUMP_SPEED := 4.0
|
const JUMP_SPEED := 4.0
|
||||||
|
var mouse_sensitivity := 0.005
|
||||||
|
var rotation_x := 0.0
|
||||||
|
var rotation_y := 0.0
|
||||||
|
var cameraMoveMode := false
|
||||||
|
|
||||||
@export var camera_path: NodePath
|
@export var camera_path: NodePath
|
||||||
@onready var cam: Camera3D = get_node(camera_path) if camera_path != NodePath("") else null
|
@onready var cam: Camera3D = get_node(camera_path) if camera_path != NodePath("") else null
|
||||||
@ -53,3 +57,21 @@ func _integrate_forces(state):
|
|||||||
|
|
||||||
if on_floor and Input.is_action_just_pressed("ui_accept"):
|
if on_floor and Input.is_action_just_pressed("ui_accept"):
|
||||||
linear_velocity.y = JUMP_SPEED
|
linear_velocity.y = JUMP_SPEED
|
||||||
|
|
||||||
|
func _input(event):
|
||||||
|
if event is InputEventMouseButton:
|
||||||
|
if event.button_index == MOUSE_BUTTON_MIDDLE:
|
||||||
|
if event.pressed:
|
||||||
|
cameraMoveMode = true
|
||||||
|
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||||
|
else:
|
||||||
|
cameraMoveMode = false
|
||||||
|
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
|
||||||
|
|
||||||
|
if event is InputEventMouseMotion and cameraMoveMode:
|
||||||
|
rotation_x -= event.relative.y * mouse_sensitivity
|
||||||
|
rotation_y -= event.relative.x * mouse_sensitivity
|
||||||
|
rotation_x = clamp(rotation_x, deg_to_rad(-90), deg_to_rad(90)) # Prevent flipping
|
||||||
|
|
||||||
|
$Camera3D.rotation.x = rotation_x
|
||||||
|
rotation.y = rotation_y
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user