Add WIP camera movement
This commit is contained in:
parent
d138db341d
commit
aacfc4d78e
113
node_3d.tscn
113
node_3d.tscn
File diff suppressed because one or more lines are too long
|
@ -7,3 +7,6 @@
|
||||||
collision_layer = 4
|
collision_layer = 4
|
||||||
collision_mask = 31
|
collision_mask = 31
|
||||||
script = ExtResource("2_14ipn")
|
script = ExtResource("2_14ipn")
|
||||||
|
|
||||||
|
[node name="Label3D" parent="." index="4"]
|
||||||
|
text = "awawawawawa"
|
||||||
|
|
|
@ -27,15 +27,25 @@ config/name="TowerGame3D"
|
||||||
run/main_scene="uid://bwftban1ppo17"
|
run/main_scene="uid://bwftban1ppo17"
|
||||||
config/features=PackedStringArray("4.4")
|
config/features=PackedStringArray("4.4")
|
||||||
config/icon="uid://u1hpdb62rxlc"
|
config/icon="uid://u1hpdb62rxlc"
|
||||||
|
addons/icon_finder/preview_size=24
|
||||||
|
|
||||||
|
[autoload]
|
||||||
|
|
||||||
|
IconsFonts="*res://addons/icons-fonts/icons_fonts/IconsFonts.gd"
|
||||||
|
|
||||||
[debug]
|
[debug]
|
||||||
|
|
||||||
|
settings/stdout/print_fps=true
|
||||||
shapes/navigation/enable_edge_connections=false
|
shapes/navigation/enable_edge_connections=false
|
||||||
shapes/navigation/enable_edge_connections_xray=false
|
shapes/navigation/enable_edge_connections_xray=false
|
||||||
shapes/navigation/enable_edge_lines_xray=false
|
shapes/navigation/enable_edge_lines_xray=false
|
||||||
shapes/navigation/enable_link_connections_xray=false
|
shapes/navigation/enable_link_connections_xray=false
|
||||||
shapes/navigation/enable_agent_paths_xray=false
|
shapes/navigation/enable_agent_paths_xray=false
|
||||||
|
|
||||||
|
[display]
|
||||||
|
|
||||||
|
window/vsync/vsync_mode=2
|
||||||
|
|
||||||
[editor]
|
[editor]
|
||||||
|
|
||||||
version_control/plugin_name="GitPlugin"
|
version_control/plugin_name="GitPlugin"
|
||||||
|
@ -43,12 +53,44 @@ version_control/autoload_on_startup=true
|
||||||
|
|
||||||
[editor_plugins]
|
[editor_plugins]
|
||||||
|
|
||||||
enabled=PackedStringArray("res://addons/GPUTrail/plugin.cfg", "res://addons/PathMesh3D/plugin.cfg", "res://addons/git_describe/plugin.cfg", "res://addons/resources_spreadsheet_view/plugin.cfg")
|
enabled=PackedStringArray("res://addons/GPUTrail/plugin.cfg", "res://addons/PathMesh3D/plugin.cfg", "res://addons/git_describe/plugin.cfg", "res://addons/icons-fonts/plugin.cfg", "res://addons/rakugo-nodes/plugin.cfg", "res://addons/resources_spreadsheet_view/plugin.cfg")
|
||||||
|
|
||||||
[global_group]
|
[global_group]
|
||||||
|
|
||||||
Enemies=""
|
Enemies=""
|
||||||
|
|
||||||
|
[input]
|
||||||
|
|
||||||
|
camera_forward={
|
||||||
|
"deadzone": 0.2,
|
||||||
|
"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,"location":0,"echo":false,"script":null)
|
||||||
|
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":3,"axis_value":-1.0,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
camera_backward={
|
||||||
|
"deadzone": 0.2,
|
||||||
|
"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,"location":0,"echo":false,"script":null)
|
||||||
|
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":3,"axis_value":1.0,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
camera_left={
|
||||||
|
"deadzone": 0.2,
|
||||||
|
"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,"location":0,"echo":false,"script":null)
|
||||||
|
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":2,"axis_value":-1.0,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
camera_right={
|
||||||
|
"deadzone": 0.2,
|
||||||
|
"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,"location":0,"echo":false,"script":null)
|
||||||
|
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":2,"axis_value":1.0,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
camera_set_target={
|
||||||
|
"deadzone": 0.2,
|
||||||
|
"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)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
[layer_names]
|
[layer_names]
|
||||||
|
|
||||||
3d_render/layer_1="Terrain"
|
3d_render/layer_1="Terrain"
|
||||||
|
@ -68,6 +110,10 @@ Enemies=""
|
||||||
3d/default_edge_connection_margin=0.6
|
3d/default_edge_connection_margin=0.6
|
||||||
3d/default_link_connection_radius=0.5
|
3d/default_link_connection_radius=0.5
|
||||||
|
|
||||||
|
[physics]
|
||||||
|
|
||||||
|
common/physics_interpolation=true
|
||||||
|
|
||||||
[rendering]
|
[rendering]
|
||||||
|
|
||||||
lights_and_shadows/directional_shadow/soft_shadow_filter_quality=0
|
lights_and_shadows/directional_shadow/soft_shadow_filter_quality=0
|
||||||
|
|
|
@ -80,6 +80,7 @@ func fire_at_target() -> void:
|
||||||
|
|
||||||
bullet.look_at(aim_target)
|
bullet.look_at(aim_target)
|
||||||
bullet.apply_impulse((aim_target - bullet.global_position).normalized()*shot_impulse)
|
bullet.apply_impulse((aim_target - bullet.global_position).normalized()*shot_impulse)
|
||||||
|
bullet.angular_velocity = (bullet.global_basis * Vector3(0,0,-10))
|
||||||
current_target = null
|
current_target = null
|
||||||
ammo -= 1
|
ammo -= 1
|
||||||
if ammo <= 0:
|
if ammo <= 0:
|
||||||
|
|
|
@ -5,7 +5,7 @@ extends RigidBody3D
|
||||||
@export var lifetime: float = 2.0
|
@export var lifetime: float = 2.0
|
||||||
|
|
||||||
func _on_body_entered(body: Node) -> void:
|
func _on_body_entered(body: Node) -> void:
|
||||||
print("Bullet collided with %s" % body.name)
|
#print("Bullet collided with %s" % body.name)
|
||||||
if body is Unit:
|
if body is Unit:
|
||||||
var speed: float = linear_velocity.length()
|
var speed: float = linear_velocity.length()
|
||||||
var damage: float = speed * damage_per_speed
|
var damage: float = speed * damage_per_speed
|
||||||
|
|
|
@ -0,0 +1,86 @@
|
||||||
|
extends Camera3D
|
||||||
|
|
||||||
|
@export var pan_speed: float = 10
|
||||||
|
var focus_offset: Vector3 = Vector3(10, 10, 10)
|
||||||
|
var focus_object: Node3D = null
|
||||||
|
var focus_position: Vector3
|
||||||
|
|
||||||
|
var last_mouse_position: Vector2
|
||||||
|
|
||||||
|
@onready var focus_marker: Node3D = $"Camera Focus"
|
||||||
|
|
||||||
|
func _physics_process(delta: float) -> void:
|
||||||
|
var mouse_position: Vector2 = get_viewport().get_mouse_position()
|
||||||
|
var ray_origin: Vector3 = project_ray_origin(mouse_position)
|
||||||
|
var ray_normal: Vector3 = ray_origin + project_ray_normal(mouse_position) * 200
|
||||||
|
var params = PhysicsRayQueryParameters3D.create(ray_origin, ray_normal)
|
||||||
|
var result: Dictionary = get_world_3d().direct_space_state.intersect_ray(params)
|
||||||
|
if result.has("position"):
|
||||||
|
DebugDraw3D.draw_sphere(result["position"], 0.5, Color.REBECCA_PURPLE)
|
||||||
|
if Input.is_action_just_released("camera_set_target"):
|
||||||
|
if result.has("collider") and !(result["collider"] is GridMap):
|
||||||
|
focus_object = result["collider"]
|
||||||
|
else:
|
||||||
|
focus_object = null
|
||||||
|
focus_position = result["position"]
|
||||||
|
|
||||||
|
if focus_object != null:
|
||||||
|
focus_position = focus_object.global_position
|
||||||
|
|
||||||
|
process_focus_movement(delta)
|
||||||
|
process_camera_rotation(delta)
|
||||||
|
|
||||||
|
var target_position: Vector3 = focus_position + focus_offset
|
||||||
|
if target_position.distance_squared_to(global_position) > 0:
|
||||||
|
global_position = global_position.move_toward(target_position, 30*(1/60.0))
|
||||||
|
else:
|
||||||
|
look_at(focus_position)
|
||||||
|
#global_position = global_position.lerp(target_position, 0.05)
|
||||||
|
|
||||||
|
#basis = basis.slerp(Basis.looking_at(focus_position - global_position), 0.05)
|
||||||
|
|
||||||
|
focus_marker.global_position = focus_position
|
||||||
|
#look_at(focus_position)
|
||||||
|
|
||||||
|
|
||||||
|
func process_focus_movement(delta: float) -> void:
|
||||||
|
var camera_forwards: Vector3 = -global_basis.z
|
||||||
|
camera_forwards = camera_forwards.slide(Vector3.UP).normalized()
|
||||||
|
|
||||||
|
var input_basis: Basis = Basis.looking_at(camera_forwards)
|
||||||
|
|
||||||
|
var x_input: float = Input.get_axis("camera_left", "camera_right")
|
||||||
|
var y_input: float = Input.get_axis("camera_backward", "camera_forward")
|
||||||
|
var input: Vector3 = Vector3(x_input, 0, -y_input).limit_length(1)
|
||||||
|
if input.is_zero_approx():
|
||||||
|
return
|
||||||
|
if focus_object != null:
|
||||||
|
focus_object = null
|
||||||
|
input = input_basis * input
|
||||||
|
|
||||||
|
var movement: Vector3 = input * pan_speed * delta
|
||||||
|
global_position += movement
|
||||||
|
focus_position += movement
|
||||||
|
|
||||||
|
# handle moving on/off ramps
|
||||||
|
var params: PhysicsRayQueryParameters3D = PhysicsRayQueryParameters3D.new()
|
||||||
|
params.from = focus_position + Vector3(0,2,0)
|
||||||
|
params.to = focus_position - Vector3(0,2,0)
|
||||||
|
var result: Dictionary = get_world_3d().direct_space_state.intersect_ray(params)
|
||||||
|
if result.has("position"):
|
||||||
|
focus_position = result["position"]
|
||||||
|
|
||||||
|
|
||||||
|
DebugDraw3D.draw_gizmo(Transform3D(input_basis, focus_position))
|
||||||
|
|
||||||
|
func process_camera_rotation(delta: float) -> void:
|
||||||
|
var mouse_position: Vector2 = get_viewport().get_mouse_position()
|
||||||
|
var mouse_movement: Vector2 = mouse_position - last_mouse_position
|
||||||
|
last_mouse_position = mouse_position
|
||||||
|
if Input.is_mouse_button_pressed(MOUSE_BUTTON_RIGHT):
|
||||||
|
|
||||||
|
focus_offset = focus_offset.rotated(Vector3.UP, -mouse_movement.x * 0.006)
|
||||||
|
var vertical_axis: Vector3 = focus_offset.cross(Vector3.UP).normalized()
|
||||||
|
focus_offset = focus_offset.rotated(vertical_axis, mouse_movement.y * 0.006)
|
||||||
|
global_position = focus_position + focus_offset
|
||||||
|
look_at(focus_position)
|
|
@ -0,0 +1 @@
|
||||||
|
uid://tx3j02eib7ba
|
|
@ -0,0 +1,6 @@
|
||||||
|
extends Node3D
|
||||||
|
|
||||||
|
@export var movement_speed: float = 5.0
|
||||||
|
#@export_node_path("Camera3D") var camera_path: NodePath
|
||||||
|
|
||||||
|
@onready var camera: Camera3D = get_viewport().get_camera_3d()
|
|
@ -0,0 +1 @@
|
||||||
|
uid://jinwrvx7tmqy
|
|
@ -66,7 +66,7 @@ func unstuck() -> void:
|
||||||
|
|
||||||
func hurt(damage: float) -> void:
|
func hurt(damage: float) -> void:
|
||||||
hp -= damage
|
hp -= damage
|
||||||
print("%s hit for %f damage, HP=%f" % [name, damage, hp])
|
#print("%s hit for %f damage, HP=%f" % [name, damage, hp])
|
||||||
if hp <= 0:
|
if hp <= 0:
|
||||||
die()
|
die()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue