drag rework
This commit is contained in:
parent
a425f62267
commit
3d81c4af5f
18 changed files with 47 additions and 267 deletions
|
|
@ -2,7 +2,15 @@ extends Camera3D
|
|||
|
||||
const SENSITIVITY = 0.01
|
||||
|
||||
var plane_position: Vector3
|
||||
@onready var drag_raycast: RayCast3D = $DragRaycast
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
drag_raycast.target_position = project_local_ray_normal(get_viewport().get_mouse_position()) * 10.0
|
||||
if drag_raycast.is_colliding():
|
||||
plane_position = drag_raycast.get_collision_point()
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if Input.is_action_pressed("drag_camera") and event is InputEventMouseMotion:
|
||||
global_position -= global_basis.x * event.relative.x * SENSITIVITY
|
||||
global_position += global_basis.y * event.relative.y * SENSITIVITY
|
||||
global_position -= Vector3.RIGHT * event.relative.x * SENSITIVITY
|
||||
global_position += Vector3.FORWARD * event.relative.y * SENSITIVITY
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@ func _process(_delta: float) -> void:
|
|||
if dragged == false:
|
||||
return
|
||||
var camera: Camera3D = get_viewport().get_camera_3d()
|
||||
var new_position: Vector3 = camera.project_position(get_viewport().get_mouse_position(),(-camera.basis.z).dot(camera.to_local(global_position)))
|
||||
global_position = new_position
|
||||
#var new_position: Vector3 = camera.project_position(get_viewport().get_mouse_position(),(-camera.basis.z).dot(camera.to_local(global_position)))
|
||||
global_position = camera.plane_position
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT:
|
||||
|
|
|
|||
|
|
@ -1,6 +0,0 @@
|
|||
extends Node
|
||||
|
||||
@export var node: Node3D
|
||||
|
||||
func destruct() -> void:
|
||||
node.queue_free()
|
||||
|
|
@ -1 +0,0 @@
|
|||
uid://co33kqhl3n06u
|
||||
11
src/interactible/interactible.gd
Normal file
11
src/interactible/interactible.gd
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
extends ConfirmationDialog
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
pass
|
||||
1
src/interactible/interactible.gd.uid
Normal file
1
src/interactible/interactible.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bl0ojhc0thk1p
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
extends Area3D
|
||||
|
||||
class_name InteractionReciever
|
||||
|
||||
signal interaction_start(source: InteractionSource)
|
||||
|
||||
func _ready() -> void:
|
||||
area_entered.connect(on_area_entered)
|
||||
area_exited.connect(on_area_exited)
|
||||
|
||||
func on_area_entered(area: Area3D):
|
||||
if area is InteractionSource:
|
||||
area.interaction_requested.connect(interaction_start.emit)
|
||||
|
||||
func on_area_exited(area: Area3D):
|
||||
if area is InteractionSource:
|
||||
area.interaction_requested.disconnect(interaction_start.emit)
|
||||
|
|
@ -1 +0,0 @@
|
|||
uid://mjx50qh1bwv3
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
extends Area3D
|
||||
|
||||
class_name InteractionSource
|
||||
|
||||
@export var interaction_dialog: ConfirmationDialog
|
||||
var recievers: int = 0
|
||||
|
||||
signal interaction_requested
|
||||
signal interaction_closed
|
||||
signal interaction_reciever_entered(reicever: InteractionReciever)
|
||||
signal interaction_reciever_exited(reicever: InteractionReciever)
|
||||
|
||||
func _ready() -> void:
|
||||
area_entered.connect(on_area_entered)
|
||||
area_exited.connect(on_area_exited)
|
||||
interaction_dialog.canceled.connect(interaction_closed.emit)
|
||||
interaction_dialog.confirmed.connect(interaction_closed.emit)
|
||||
|
||||
func on_area_entered(area: Area3D):
|
||||
if area is InteractionReciever:
|
||||
interaction_reciever_entered.emit(area)
|
||||
recievers += 1
|
||||
|
||||
func on_area_exited(area: Area3D):
|
||||
if area is InteractionReciever:
|
||||
interaction_reciever_exited.emit(area)
|
||||
recievers -= 1
|
||||
|
||||
func request_interaction() -> void:
|
||||
if recievers == 0:
|
||||
interaction_closed.emit()
|
||||
return
|
||||
interaction_requested.emit()
|
||||
interaction_dialog.popup_centered()
|
||||
|
|
@ -1 +0,0 @@
|
|||
uid://ctu7escah5lo1
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
extends Node
|
||||
|
||||
@export var rotated: Node3D
|
||||
@export var proximity_radius: float
|
||||
@export var modification_curve: Curve
|
||||
var start_rotation
|
||||
var reciever: InteractionReciever
|
||||
|
||||
func _ready() -> void:
|
||||
start_rotation = rotated.quaternion
|
||||
|
||||
func _on_interaction_area_interaction_reciever_entered(rec: InteractionReciever) -> void:
|
||||
if reciever == null:
|
||||
reciever = rec
|
||||
|
||||
|
||||
func _on_interaction_area_interaction_reciever_exited(rec: InteractionReciever) -> void:
|
||||
if reciever == rec:
|
||||
reciever = null
|
||||
rotated.quaternion = start_rotation
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
if reciever == null:
|
||||
rotated.quaternion = start_rotation
|
||||
return
|
||||
|
||||
var camera: Camera3D = get_viewport().get_camera_3d()
|
||||
var rotation_direction : float = -sign(camera.basis.x.dot(reciever.global_position - rotated.global_position))
|
||||
var result_quaternion: Quaternion = Quaternion(-camera.basis.z,PI + 1.5707963267948966 * rotation_direction)
|
||||
var distance_without_y: float = Vector2(rotated.global_position.x,rotated.global_position.z).distance_to(Vector2(reciever.global_position.x,reciever.global_position.z))
|
||||
var calculated_angle: Quaternion = start_rotation.slerp(result_quaternion,modification_curve.sample(clamp(proximity_radius/distance_without_y,0,1)))
|
||||
rotated.quaternion = calculated_angle
|
||||
|
|
@ -1 +0,0 @@
|
|||
uid://e8xu57ewvb5a
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
extends Node
|
||||
|
||||
@export var node: Node3D
|
||||
@onready var start_position: Vector3 = node.global_position
|
||||
|
||||
func return_to_start() -> void:
|
||||
node.global_position = start_position
|
||||
|
|
@ -1 +0,0 @@
|
|||
uid://b1gv6dt8bwj2p
|
||||
Loading…
Add table
Add a link
Reference in a new issue