mirror of
https://github.com/godotengine/godot-demo-projects.git
synced 2026-01-06 07:50:22 +01:00
Add Physics Tests project
This commit is contained in:
35
3d/physics_tests/utils/camera_orbit.gd
Normal file
35
3d/physics_tests/utils/camera_orbit.gd
Normal file
@@ -0,0 +1,35 @@
|
||||
extends Camera
|
||||
|
||||
|
||||
const ROTATION_COEFF = 0.02
|
||||
|
||||
var _rotation_enabled = false
|
||||
var _rotation_pivot
|
||||
|
||||
|
||||
func _ready():
|
||||
call_deferred("_initialize_pivot")
|
||||
|
||||
|
||||
func _unhandled_input(event):
|
||||
var mouse_button_event = event as InputEventMouseButton
|
||||
if mouse_button_event:
|
||||
if mouse_button_event.button_index == BUTTON_LEFT:
|
||||
_rotation_enabled = mouse_button_event.pressed
|
||||
return
|
||||
|
||||
if not _rotation_enabled:
|
||||
return
|
||||
|
||||
var mouse_motion_event = event as InputEventMouseMotion
|
||||
if mouse_motion_event:
|
||||
var rotation_delta = mouse_motion_event.relative.x
|
||||
_rotation_pivot.rotate(Vector3.UP, -rotation_delta * ROTATION_COEFF)
|
||||
|
||||
|
||||
func _initialize_pivot():
|
||||
_rotation_pivot = Spatial.new()
|
||||
var camera_parent = get_parent()
|
||||
camera_parent.add_child(_rotation_pivot)
|
||||
camera_parent.remove_child(self)
|
||||
_rotation_pivot.add_child(self)
|
||||
Reference in New Issue
Block a user