Upload files to "/"

This commit is contained in:
RK117 2023-11-16 11:00:57 -08:00
parent e1f512e30b
commit 8c3cb0871c
5 changed files with 240 additions and 0 deletions

30
MoveCam.gd Normal file
View File

@ -0,0 +1,30 @@
extends Camera3D
@export var movespeed: float
@export var rotatespeed: float
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
if Input.is_action_pressed("W"):
self.position += global_transform.basis.y*movespeed*delta
if Input.is_action_pressed("S"):
self.position += global_transform.basis.y*-movespeed*delta
if Input.is_action_pressed("A"):
self.position += global_transform.basis.x*-movespeed*delta
if Input.is_action_pressed("D"):
self.position += global_transform.basis.x*movespeed*delta
if Input.is_action_pressed("zoom in"):
self.position += Vector3(0,-movespeed*delta,0)
if Input.is_action_pressed("zoom out"):
self.position += Vector3(0,movespeed*delta,0)
if Input.is_action_pressed("rotate right"):
self.rotation += Vector3(0,-rotatespeed*delta,0)
if Input.is_action_pressed("rotate left"):
self.rotation += Vector3(0,rotatespeed*delta,0)
pass

95
Navdrone.gd Normal file
View File

@ -0,0 +1,95 @@
extends CharacterBody3D
@export var speed = 2
@export var accel = 2
@onready var nav: NavigationAgent3D = $NavigationAgent3D
@export var cam: Camera3D
@export var navres: NavigationRegion3D
@export var block: PackedScene
var canMove
var current = 0
var path: PackedVector3Array
signal redid_navmesh
var destroy: Array
var rayOrigin= Vector3()
var rayEnd= Vector3()
var pathDone = true
func _ready():
canMove = false
destroy = Array()
print("new drone!")
func _physics_process(delta):
var direction = Vector3()
#if Input.is_action_just_pressed("left_click"):
# _do_path(_click_intersect())
if Time.get_ticks_msec()> 20 && current < (path.size()-1) && canMove:
var next = path[current+1]
look_at(Vector3(next.x,global_position.y,next.z))
direction = next - global_position
direction = direction.normalized()
velocity = velocity.lerp(direction*speed, accel * delta);
if self.position.distance_to(next)<nav.path_desired_distance:
current=current+1
elif current == path.size()-1 && !pathDone:
velocity = velocity*0
cleanUp()
pathDone = true
await get_tree().create_timer(0.05).timeout
#navres.bake_navigation_mesh()
move_and_slide()
func _do_path(goal:Vector3):
_coverPath(goal)
navres.bake_navigation_mesh()
current = 0
pathDone = false
func _click_intersect():
cleanUp()
var space_state = get_world_3d().direct_space_state
var mouse_position = get_viewport().get_mouse_position()
rayOrigin = cam.project_ray_origin(mouse_position)
rayEnd = rayOrigin + cam.project_ray_normal(mouse_position)*2000
var query = PhysicsRayQueryParameters3D.create(rayOrigin,rayEnd)
var intersection = space_state.intersect_ray(query)
if intersection.is_empty():
intersection = get_global_position()
print("nothing found")
#else:
#print (get_name())
return intersection.position
func _coverPath(Target:Vector3): #generates navmesh obstacles where drone is going
path = NavigationServer3D.map_get_path(get_world_3d().get_navigation_map(),global_position,Target,true)
#for point in path:
# var barrier = block.instantiate()
# navres.add_child(barrier)
# barrier.position=point
# destroy.append(barrier)
for n in (path.size()-1):
var barrier = block.instantiate()
navres.add_child(barrier)
barrier.position=(path[n+1]-path[n])/2+path[n]
barrier.scale=Vector3(barrier.scale.x,1,(path[n+1]-path[n]).length())
barrier.look_at(path[n+1])
destroy.append(barrier)
func cleanUp(): ##cleans navmesh obstacles
for d in destroy:
d.queue_free()
destroy.clear()
#func _on_navigation_agent_3d_navigation_finished():
#cleanUp()

Binary file not shown.

33
navdrone.tscn Normal file
View File

@ -0,0 +1,33 @@
[gd_scene load_steps=5 format=3 uid="uid://dp41b4l8rtmd"]
[ext_resource type="Script" path="res://Navdrone.gd" id="1_8s1ap"]
[ext_resource type="PackedScene" uid="uid://dyajrcmw1xovo" path="res://testbin.tscn" id="2_icho2"]
[ext_resource type="ArrayMesh" uid="uid://c63wm5ikugi4n" path="res://dmesho.obj" id="3_i17ly"]
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_414ve"]
[node name="Navdrone" type="CharacterBody3D"]
transform = Transform3D(2, 0, 0, 0, 2, 0, 0, 0, 2, 0, 2.048, 0)
script = ExtResource("1_8s1ap")
speed = 15
block = ExtResource("2_icho2")
[node name="DroneMeshInstance3D" type="MeshInstance3D" parent="."]
transform = Transform3D(0.5, 0, 0, 0, 0.5, 0, 0, 0, -0.5, 0, 0, 0)
mesh = ExtResource("3_i17ly")
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
shape = SubResource("CapsuleShape3D_414ve")
[node name="NavigationAgent3D" type="NavigationAgent3D" parent="."]
path_desired_distance = 3.0
target_desired_distance = 3.0
path_max_distance = 13.01
avoidance_enabled = true
time_horizon_agents = 4.46
time_horizon_obstacles = 1.0
max_speed = 2.0
debug_enabled = true
[connection signal="navigation_finished" from="NavigationAgent3D" to="." method="_on_navigation_agent_3d_navigation_finished"]
[connection signal="path_changed" from="NavigationAgent3D" to="." method="_on_navigation_agent_3d_path_changed"]

82
project.godot Normal file
View File

@ -0,0 +1,82 @@
; Engine configuration file.
; It's best edited using the editor UI and not directly,
; since the parameters that go here are not all obvious.
;
; Format:
; [section] ; section goes between []
; param=value ; assign values to parameters
config_version=5
[application]
config/name="rtstest"
run/main_scene="res://DronePather.tscn"
config/features=PackedStringArray("4.1", "Mobile")
config/icon="res://icon.svg"
[filesystem]
import/fbx/enabled=false
[input]
left_click={
"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)
]
}
right_click={
"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":3,"canceled":false,"pressed":false,"double_click":false,"script":null)
]
}
W={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":119,"echo":false,"script":null)
]
}
A={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":97,"echo":false,"script":null)
]
}
S={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"echo":false,"script":null)
]
}
D={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"echo":false,"script":null)
]
}
"rotate left"={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":81,"key_label":0,"unicode":113,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194319,"key_label":0,"unicode":0,"echo":false,"script":null)
]
}
"rotate right"={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":69,"key_label":0,"unicode":101,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194321,"key_label":0,"unicode":0,"echo":false,"script":null)
]
}
"zoom in"={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194320,"key_label":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194325,"key_label":0,"unicode":0,"echo":false,"script":null)
]
}
"zoom out"={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194322,"key_label":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194326,"key_label":0,"unicode":0,"echo":false,"script":null)
]
}
[rendering]
renderer/rendering_method="gl_compatibility"
textures/vram_compression/import_etc2_astc=true