Add camera rotation and move to point
This commit is contained in:
parent
c365f28395
commit
e38abce727
@ -19,6 +19,19 @@ config/icon="res://icon.svg"
|
||||
version_control/plugin_name="GitPlugin"
|
||||
version_control/autoload_on_startup=true
|
||||
|
||||
[input]
|
||||
|
||||
move={
|
||||
"deadzone": 0.5,
|
||||
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":1,"canceled":false,"pressed":false,"double_click":false,"script":null)
|
||||
]
|
||||
}
|
||||
move_camera={
|
||||
"deadzone": 0.5,
|
||||
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":2,"canceled":false,"pressed":false,"double_click":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
[navigation]
|
||||
|
||||
3d/default_cell_size=0.1
|
||||
|
||||
21
scenes/camera_rotation.gd
Normal file
21
scenes/camera_rotation.gd
Normal file
@ -0,0 +1,21 @@
|
||||
extends Node3D
|
||||
|
||||
var last_mouse_pos: Vector2 = Vector2.ZERO
|
||||
|
||||
func rotate_camera():
|
||||
var pos = get_viewport().get_mouse_position()
|
||||
var change = pos - last_mouse_pos
|
||||
|
||||
var rotate_amt = Vector3(-change.y, -change.x, 0) * 0.01
|
||||
var new_rotation = rotation + rotate_amt
|
||||
if new_rotation.y > PI*2:
|
||||
new_rotation.y -= PI*2
|
||||
elif new_rotation.y < 0:
|
||||
new_rotation.y += PI*2
|
||||
|
||||
rotation = new_rotation.clamp(Vector3(deg_to_rad(-80), -1, 0), Vector3(deg_to_rad(1), PI*2+1, 0))
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if Input.is_action_pressed("move_camera"):
|
||||
rotate_camera()
|
||||
last_mouse_pos = get_viewport().get_mouse_position()
|
||||
@ -1,6 +1,7 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://cu1bnkqxd1nyh"]
|
||||
[gd_scene load_steps=5 format=3 uid="uid://cu1bnkqxd1nyh"]
|
||||
|
||||
[ext_resource type="Script" path="res://character.gd" id="1_32tgv"]
|
||||
[ext_resource type="Script" path="res://scripts/character.gd" id="1_32tgv"]
|
||||
[ext_resource type="Script" path="res://scenes/camera_rotation.gd" id="2_s5f3j"]
|
||||
|
||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_4w3u7"]
|
||||
|
||||
@ -8,6 +9,7 @@
|
||||
|
||||
[node name="Character" type="CharacterBody3D"]
|
||||
script = ExtResource("1_32tgv")
|
||||
raycast_mask = 2
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
|
||||
@ -20,7 +22,9 @@ skeleton = NodePath("../..")
|
||||
[node name="NavigationAgent3D" type="NavigationAgent3D" parent="."]
|
||||
debug_enabled = true
|
||||
|
||||
[node name="Timer" type="Timer" parent="."]
|
||||
wait_time = 2.0
|
||||
one_shot = true
|
||||
autostart = true
|
||||
[node name="Pivot" type="Node3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 0.859273, 0.511518, 0, -0.511518, 0.859273, 0, 0, 0)
|
||||
script = ExtResource("2_s5f3j")
|
||||
|
||||
[node name="Camera3D" type="Camera3D" parent="Pivot"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 6.82489)
|
||||
@ -1,6 +1,6 @@
|
||||
[gd_scene load_steps=5 format=3 uid="uid://n1o3m7g342dk"]
|
||||
|
||||
[ext_resource type="Script" path="res://dock_link.gd" id="1_a7ngo"]
|
||||
[ext_resource type="Script" path="res://scripts/dock_link.gd" id="1_a7ngo"]
|
||||
|
||||
[sub_resource type="CylinderMesh" id="CylinderMesh_oms63"]
|
||||
|
||||
@ -27,6 +27,8 @@ mesh = SubResource("CylinderMesh_oms63")
|
||||
navigation_mesh = SubResource("NavigationMesh_uiteq")
|
||||
|
||||
[node name="Dock" type="CSGCombiner3D" parent="NavigationRegion3D"]
|
||||
use_collision = true
|
||||
collision_layer = 3
|
||||
|
||||
[node name="CSGBox3D" type="CSGBox3D" parent="NavigationRegion3D/Dock"]
|
||||
transform = Transform3D(4.44697, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -4.61133)
|
||||
@ -1,7 +1,8 @@
|
||||
[gd_scene load_steps=5 format=3 uid="uid://b5i2qmhgqp617"]
|
||||
[gd_scene load_steps=6 format=3 uid="uid://b5i2qmhgqp617"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://n1o3m7g342dk" path="res://dock.tscn" id="1_1av3j"]
|
||||
[ext_resource type="PackedScene" uid="uid://cu1bnkqxd1nyh" path="res://Character.tscn" id="1_ptn04"]
|
||||
[ext_resource type="PackedScene" uid="uid://n1o3m7g342dk" path="res://scenes/dock.tscn" id="1_1av3j"]
|
||||
[ext_resource type="PackedScene" uid="uid://cu1bnkqxd1nyh" path="res://scenes/character.tscn" id="1_ptn04"]
|
||||
[ext_resource type="Script" path="res://scripts/location.gd" id="3_nwpdo"]
|
||||
|
||||
[sub_resource type="NavigationMesh" id="NavigationMesh_nu02n"]
|
||||
vertices = PackedVector3Array(-19.6, 1.7, -42.537, -19, 1.7, -42.737, -10.9, 1.7, -48.237, -49, 1.7, -41.337, -20.1, 1.7, -41.237, -20.1, 1.7, -41.837, -9.9, 1.7, -48.437, -9.9, 1.7, -94.337, -49, 1.7, -94.337, -7.8, 1.7, -48.037, -7.7, 1.7, -94.337, -5.7, 1.7, -47.637, -5.6, 1.7, -94.337, -3.6, 1.7, -47.237, -3.5, 1.7, -94.337, -1.5, 1.7, -46.837, -1.4, 1.7, -94.337, 0.600002, 1.7, -46.437, 0.700001, 1.7, -94.337, 2.7, 1.7, -46.037, 2.8, 1.7, -94.337, 4.8, 1.7, -45.637, 4.9, 1.7, -94.337, 6.9, 1.7, -45.237, 7, 1.7, -94.337, 9, 1.7, -44.837, 9.1, 1.7, -94.337, 25.6, 1.7, -29.637, 25.8, 1.7, -29.137, 49, 1.7, -29.137, 10.7, 1.7, -44.437, 49, 1.7, -94.337, -20.4, 1.7, -37.237, -49, 1.7, -37.237, -20.8, 1.7, -31.937, -49, 1.7, -31.937, -21.2, 1.7, -26.737, -49, 1.7, -26.737, 25.7, 1.7, -28.837, 26.1, 1.7, -26.337, 49, 1.7, -26.437, -21.6, 1.7, -21.537, -49, 1.7, -21.537, 26.5, 1.7, -23.237, 49, 1.7, -23.337, 26.9, 1.7, -20.137, 49, 1.7, -20.237, -22, 1.7, -16.337, -49, 1.7, -16.337, 27.3, 1.7, -17.037, 49, 1.7, -17.137, 27.7, 1.7, -13.937, 49, 1.7, -14.037, -22.1, 1.7, -15.137, -49, 1.7, -15.037, -13.5, 1.7, -0.336998, -21.3, 1.7, -13.237, -21.7, 1.7, -13.637, -22, 1.7, -14.237, -3.9, 1.7, 48.963, -5.5, 1.7, 3.063, -12.8, 1.7, 0.163002, -49, 1.7, 48.963, -3.9, 1.7, 3.36301, -4.7, 1.7, 3.36301, 28.1, 1.7, -10.837, 49, 1.7, -10.937, 28.3, 1.7, -9.437, 28.2, 1.7, -8.237, 49, 1.7, -8.237, 27.5, 1.7, -7.237, 23.4, 1.7, 1.563, 20.9, 1.7, 2.96301, 19.8, 1.7, 3.36301, 19, 1.7, 48.963, 22.9, 1.7, 2.063, 49, 1.7, 48.963, 19, 1.7, 3.36301)
|
||||
@ -23,6 +24,7 @@ navigation_mesh = SubResource("NavigationMesh_nu02n")
|
||||
|
||||
[node name="Level" type="CSGCombiner3D" parent="NavigationRegion3D"]
|
||||
use_collision = true
|
||||
collision_layer = 3
|
||||
|
||||
[node name="CSGBox3D" type="CSGBox3D" parent="NavigationRegion3D/Level"]
|
||||
transform = Transform3D(100, 0, 0, 0, 3, 0, 0, 0, 100, 0, 0, -22.6685)
|
||||
@ -76,9 +78,13 @@ size = Vector3(0.334114, 1, 1)
|
||||
|
||||
[node name="Character" parent="." instance=ExtResource("1_ptn04")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -19.8339, 1.86631, 8.91661)
|
||||
player = true
|
||||
|
||||
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, -0.877682, 0.479243, 0, -0.479243, -0.877682, 0, 6.82306, 0)
|
||||
|
||||
[node name="Camera3D" type="Camera3D" parent="."]
|
||||
transform = Transform3D(-4.37114e-08, -0.707107, 0.707107, 0, 0.707107, 0.707107, -1, 3.09086e-08, -3.09086e-08, 10.1826, 10.1796, 0)
|
||||
|
||||
[node name="Location" type="Node3D" parent="."]
|
||||
script = ExtResource("3_nwpdo")
|
||||
@ -1,5 +1,15 @@
|
||||
extends CharacterBody3D
|
||||
|
||||
enum Actions {
|
||||
Fishing,
|
||||
Relaxing,
|
||||
}
|
||||
|
||||
@export var player: bool
|
||||
@export var action: Actions = Actions.Relaxing
|
||||
@export_category("Movement")
|
||||
@export_flags_3d_physics var raycast_mask
|
||||
|
||||
var movement_speed: float = 2.0
|
||||
var movement_target_position: Vector3 = Vector3(-3.0,0.0,3.5)
|
||||
|
||||
@ -11,7 +21,7 @@ func _ready():
|
||||
navigation_agent.path_desired_distance = 0.2
|
||||
navigation_agent.target_desired_distance = 0.5
|
||||
|
||||
actor_setup.call_deferred()
|
||||
#actor_setup.call_deferred()
|
||||
|
||||
func actor_setup():
|
||||
# Wait for the first physics frame so the NavigationServer can sync.
|
||||
@ -25,7 +35,27 @@ func actor_setup():
|
||||
func set_movement_target(movement_target: Vector3):
|
||||
navigation_agent.set_target_position(movement_target)
|
||||
|
||||
func get_point_from_mouse():
|
||||
const RAY_LENGTH = 1000
|
||||
var space_state = get_world_3d().direct_space_state
|
||||
var cam: Camera3D = $Pivot/Camera3D
|
||||
var mousepos = get_viewport().get_mouse_position()
|
||||
|
||||
var origin = cam.project_ray_origin(mousepos)
|
||||
var end = origin + cam.project_ray_normal(mousepos) * RAY_LENGTH
|
||||
var query = PhysicsRayQueryParameters3D.create(origin, end, raycast_mask)
|
||||
query.collide_with_areas = true
|
||||
|
||||
var result = space_state.intersect_ray(query)
|
||||
if result:
|
||||
return result.get("position")
|
||||
|
||||
func _physics_process(delta):
|
||||
if Input.is_action_just_pressed("move"):
|
||||
var pos = get_point_from_mouse()
|
||||
if pos:
|
||||
set_movement_target(pos)
|
||||
|
||||
if navigation_agent.is_navigation_finished():
|
||||
return
|
||||
|
||||
12
scripts/location.gd
Normal file
12
scripts/location.gd
Normal file
@ -0,0 +1,12 @@
|
||||
class_name Location extends Node3D
|
||||
|
||||
@export var Actions: Array[String]
|
||||
|
||||
# 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
|
||||
Loading…
x
Reference in New Issue
Block a user