proximity rotation
This commit is contained in:
parent
4525ab50ff
commit
3a6da57079
3 changed files with 23 additions and 12 deletions
|
|
@ -13,7 +13,7 @@ height = 0.7
|
|||
|
||||
[sub_resource type="CylinderMesh" id="CylinderMesh_627mb"]
|
||||
top_radius = 0.1
|
||||
bottom_radius = 0.1
|
||||
bottom_radius = 0.08
|
||||
height = 0.5
|
||||
|
||||
[node name="DraggableObject" type="Area3D"]
|
||||
|
|
@ -23,6 +23,9 @@ script = ExtResource("1_vcwhe")
|
|||
shape = SubResource("SphereShape3D_vcwhe")
|
||||
|
||||
[node name="InteractionArea" type="Area3D" parent="."]
|
||||
collision_layer = 2
|
||||
collision_mask = 2
|
||||
input_ray_pickable = false
|
||||
script = ExtResource("2_627mb")
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="InteractionArea"]
|
||||
|
|
@ -31,8 +34,10 @@ shape = SubResource("CapsuleShape3D_vcwhe")
|
|||
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
|
||||
mesh = SubResource("CylinderMesh_627mb")
|
||||
|
||||
[node name="ProximityRotator" type="Node" parent="."]
|
||||
[node name="ProximityRotator" type="Node" parent="." node_paths=PackedStringArray("rotated")]
|
||||
script = ExtResource("3_00eeh")
|
||||
rotated = NodePath("../MeshInstance3D")
|
||||
proximity_radius = 0.496
|
||||
|
||||
[connection signal="drag_ended" from="." to="InteractionArea" method="request_interaction"]
|
||||
[connection signal="interaction_reciever_entered" from="InteractionArea" to="ProximityRotator" method="_on_interaction_area_interaction_reciever_entered"]
|
||||
|
|
|
|||
|
|
@ -10,6 +10,9 @@ height = 1.0
|
|||
radius = 0.75
|
||||
|
||||
[node name="InteractibleObject" type="Area3D"]
|
||||
collision_layer = 2
|
||||
collision_mask = 2
|
||||
input_ray_pickable = false
|
||||
script = ExtResource("1_auicg")
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
|
||||
|
|
|
|||
|
|
@ -1,23 +1,26 @@
|
|||
extends Node
|
||||
|
||||
@export var rotated: Node3D
|
||||
@export var proximity_radius: float
|
||||
@onready var start_rotation = rotated.quaternion
|
||||
var reiciever: InteractionReciever
|
||||
var reciever: InteractionReciever
|
||||
|
||||
func _on_interaction_area_interaction_reciever_entered(reicever: InteractionReciever) -> void:
|
||||
if self.reicever == null:
|
||||
self.reciever = reicever
|
||||
func _on_interaction_area_interaction_reciever_entered(rec: InteractionReciever) -> void:
|
||||
if reciever == null:
|
||||
reciever = rec
|
||||
|
||||
|
||||
func _on_interaction_area_interaction_reciever_exited(reicever: InteractionReciever) -> void:
|
||||
if self.reicever == reicever:
|
||||
self.reciever = null
|
||||
func _on_interaction_area_interaction_reciever_exited(rec: InteractionReciever) -> void:
|
||||
if reciever == rec:
|
||||
reciever = null
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
if reiciever == null:
|
||||
if reciever == null:
|
||||
rotated.quaternion = start_rotation
|
||||
return
|
||||
|
||||
var camera: Camera3D = get_viewport().get_camera_3d()
|
||||
var angle_to: Quaternion = Quaternion(-camera.basis.z,1.5707963267948966)
|
||||
var calculated_angle: Quaternion = start_rotation.slerp()
|
||||
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 calculated_angle: Quaternion = start_rotation.slerp(result_quaternion,clamp(proximity_radius/rotated.global_position.distance_to(reciever.global_position),0,1))
|
||||
rotated.quaternion = calculated_angle
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue