Compare commits

..

No commits in common. "c6f43fac9bb1fb8fd5bbe5b36d63029be12b9ae6" and "c344755916bb6dc3235a37326d3f19ab93c8ff78" have entirely different histories.

11 changed files with 37 additions and 175 deletions

View File

@ -3,26 +3,25 @@
importer="texture"
type="CompressedTexture2D"
uid="uid://brjswv5ryy8om"
path.s3tc="res://.godot/imported/lilguy.png-051ea7725e05924272fe99d4c4cd30d6.s3tc.ctex"
path="res://.godot/imported/lilguy.png-051ea7725e05924272fe99d4c4cd30d6.ctex"
metadata={
"imported_formats": ["s3tc_bptc"],
"vram_texture": true
"vram_texture": false
}
[deps]
source_file="res://assets/images/lilguy.png"
dest_files=["res://.godot/imported/lilguy.png-051ea7725e05924272fe99d4c4cd30d6.s3tc.ctex"]
dest_files=["res://.godot/imported/lilguy.png-051ea7725e05924272fe99d4c4cd30d6.ctex"]
[params]
compress/mode=2
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=true
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
@ -32,4 +31,4 @@ process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=0
detect_3d/compress_to=1

View File

@ -3,26 +3,25 @@
importer="texture"
type="CompressedTexture2D"
uid="uid://cpov32m0nxjvh"
path.s3tc="res://.godot/imported/lilguy_arms.png-579679cf4842d72a1b6c8bc34db4fa7f.s3tc.ctex"
path="res://.godot/imported/lilguy_arms.png-579679cf4842d72a1b6c8bc34db4fa7f.ctex"
metadata={
"imported_formats": ["s3tc_bptc"],
"vram_texture": true
"vram_texture": false
}
[deps]
source_file="res://assets/images/lilguy_arms.png"
dest_files=["res://.godot/imported/lilguy_arms.png-579679cf4842d72a1b6c8bc34db4fa7f.s3tc.ctex"]
dest_files=["res://.godot/imported/lilguy_arms.png-579679cf4842d72a1b6c8bc34db4fa7f.ctex"]
[params]
compress/mode=2
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=true
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
@ -32,4 +31,4 @@ process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=0
detect_3d/compress_to=1

View File

@ -29,11 +29,9 @@ ammo_cap = 10
fire_cooldown_time = 0.2
reload_time = 1.0
bullet_scene = ExtResource("3_kpsgq")
fire_position = Vector3(0, 2.1, 0)
shot_velocity = 20.0
lead_shots = true
compensate_for_gravity = true
use_artillery_firing_solution = false
fire_position = Vector3(0, 1, 0)
shot_impulse = 100.0
lead_shot_factor = 0.01
[node name="MeshInstance3D" parent="." index="0"]
material_override = SubResource("StandardMaterial3D_cgb0l")

View File

@ -110,7 +110,6 @@ continuous_cd = true
contact_monitor = true
max_contacts_reported = 1
script = ExtResource("1_rsjgb")
damage_per_speed = 100.0
min_damage = 1.0
lifetime = 5.0

View File

@ -1,24 +0,0 @@
@tool
extends Unit
class_name Citizen
@onready var body: Sprite3D = $Body
@onready var hands: Sprite3D = $Body/Hands
func _process(delta: float) -> void:
super(delta)
var camera: Camera3D
if Engine.is_editor_hint():
camera = EditorInterface.get_editor_viewport_3d(0).get_camera_3d()
else:
camera = get_viewport().get_camera_3d()
var facing_direction: Vector3 = -global_basis.z
var camera_local_facing: Vector3 = facing_direction * camera.global_basis
var facing_away: bool = camera_local_facing.z < 0
var facing_right: bool = camera_local_facing.x > 0
body.frame = 1 if facing_away else 0
hands.frame = 1 if facing_away else 0
body.flip_h = facing_right
hands.flip_h = facing_right

View File

@ -1 +0,0 @@
uid://b7xficxq807qd

View File

@ -1,52 +0,0 @@
[gd_scene load_steps=8 format=3 uid="uid://skxli3htgn7"]
[ext_resource type="PackedScene" uid="uid://1gcj3gixy6hs" path="res://objects/units/unit.tscn" id="1_6046h"]
[ext_resource type="Script" uid="uid://b7xficxq807qd" path="res://objects/units/citizen.gd" id="2_dv62s"]
[ext_resource type="Texture2D" uid="uid://brjswv5ryy8om" path="res://assets/images/lilguy.png" id="3_pedvu"]
[ext_resource type="Texture2D" uid="uid://cpov32m0nxjvh" path="res://assets/images/lilguy_arms.png" id="4_i1unn"]
[ext_resource type="ArrayMesh" uid="uid://gf0q5hs4wjva" path="res://assets/models/Ore.obj" id="5_dds8f"]
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_vpcy6"]
albedo_texture = ExtResource("3_pedvu")
billboard_mode = 2
[sub_resource type="QuadMesh" id="QuadMesh_5xmhx"]
material = SubResource("StandardMaterial3D_vpcy6")
[node name="Citizen" instance=ExtResource("1_6046h")]
collision_layer = 8
collision_mask = 5
script = ExtResource("2_dv62s")
[node name="NavigationAgent3D" parent="." index="0"]
target_position = Vector3(21.7818, 1, 12.7739)
velocity = Vector3(0.811107, 0, -0.811107)
[node name="MeshInstance3D" parent="." index="2"]
visible = false
mesh = SubResource("QuadMesh_5xmhx")
[node name="Label3D" parent="." index="4"]
text = "HP: 100"
[node name="Body" type="Sprite3D" parent="." index="5"]
transform = Transform3D(3, 0, 0, 0, 3, 0, 0, 0, 3, 0, 0, 0)
billboard = 2
shaded = true
alpha_cut = 1
texture_filter = 0
texture = ExtResource("3_pedvu")
hframes = 2
[node name="Hands" type="Sprite3D" parent="Body" index="0"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.01)
billboard = 2
shaded = true
alpha_cut = 1
texture_filter = 0
texture = ExtResource("4_i1unn")
[node name="Held Item" type="MeshInstance3D" parent="Body/Hands" index="0"]
transform = Transform3D(0.17, 0, 0, 0, 0.17, 0, 0, 0, 0.17, 5.96046e-08, -0.0580646, -0.0773078)
mesh = ExtResource("5_dds8f")
skeleton = NodePath("../../..")

View File

@ -22,9 +22,9 @@ material = SubResource("StandardMaterial3D_jka67")
[node name="Unit" type="RigidBody3D"]
axis_lock_angular_x = true
axis_lock_angular_y = true
axis_lock_angular_z = true
physics_material_override = SubResource("PhysicsMaterial_a0tk4")
angular_damp = 20.0
script = ExtResource("1_dberb")
movement_force = 5.0
max_speed = 5.0

View File

@ -1,13 +1,13 @@
extends Node3D
class_name Building
@export_group("Defence")
@export var max_hp: int = 100 ## Amount of damage this building can sustain before being destroyed.
@export_category("Defence")
@export var max_hp: int = 100
@export_group("Stacking")
@export var can_stack: bool = true ## Whether this building can be stacked on top of other buildings.
@export var can_be_stacked_on: bool = true ## Whether this building will accept other buildings being stacked on it.
@export var stack_position: Vector3 = Vector3(0,2,0) ## The local position that stacked buildings will be placed at.
@export_category("Stacking")
@export var can_stack: bool = true
@export var can_be_stacked_on: bool = true
@export var stack_position: Vector3 = Vector3(0,2,0)
@onready var build_position: Vector3 = global_position

View File

@ -1,20 +1,12 @@
extends Building
class_name Turret
@export_group("Ammunition")
@export var ammo_cap: int = 10 ## The number of shots per "magazine", i.e. reload.
@export var fire_cooldown_time: float = 0.2 ## The time between shots, in seconds.
@export var reload_time: float = 1.0 ## The time taken to reload, in seconds.
@export_group("Bullet Spawning")
@export var bullet_scene: PackedScene = preload("res://objects/bullet.tscn") ## The entity to spawn as a bullet.
@export var fire_position: Vector3 = Vector3(0,1,0) ## The local position to fire from.
@export_group("Ballistics")
@export var shot_velocity: float = 100 ## The velocity that bullets are fired at, in m/s.
@export var lead_shots: bool = true ## Turn on to make the turret aim ahead of moving targets.
@export var compensate_for_gravity: bool = true ## Turn on to make the turret aim above distant targets to arc it's shots.
@export var use_artillery_firing_solution: bool = false ## If compensating for gravity, turn this on to make the turret aim high instead of low.
@export var ammo_cap: int = 10
@export var fire_cooldown_time: float = 0.2
@export var reload_time: float = 1.0
@export var bullet_scene: PackedScene = preload("res://objects/bullet.tscn")
@export var fire_position: Vector3 = Vector3(0,1,0)
@export var shot_impulse: float = 100
@export var lead_shot_factor: float = 0.01
enum LoadState {UNLOADED, RELOADING, LOADED}
@ -31,6 +23,7 @@ func _process(delta: float) -> void:
super(delta)
if loaded == LoadState.UNLOADED:
if consumer.take_any_item_from_storage():
#Engine.time_scale = 1.0
loaded = LoadState.RELOADING
if loaded == LoadState.RELOADING:
reload_timer += delta
@ -77,55 +70,17 @@ func fire_at_target() -> void:
#Engine.time_scale = 0.1
var bullet: RigidBody3D = bullet_scene.instantiate()
add_child(bullet)
var bullet_pos: Vector3 = to_global(fire_position)
bullet.global_position = bullet_pos
var target_range: float = bullet_pos.distance_to(current_target.global_position)
var shot_time: float = (target_range / shot_velocity)
bullet.global_position = to_global(fire_position)
var aim_target: Vector3 = current_target.global_position
if lead_shots:
aim_target += current_target.linear_velocity * shot_time
target_range = bullet_pos.distance_to(aim_target)
DebugDraw3D.draw_sphere(aim_target, 0.25, Color.RED, shot_time)
var target_range: float = global_position.distance_to(current_target.global_position)
aim_target += current_target.linear_velocity * lead_shot_factor * target_range
DebugDraw3D.draw_sphere(aim_target, 0.25, Color.RED, 0.1)
var fire_direction: Vector3
if compensate_for_gravity:
var elevation: float = find_fire_angle(target_range, aim_target.y - bullet_pos.y, use_artillery_firing_solution)
var azimuth: float = Vector3.FORWARD.signed_angle_to(aim_target-global_position, Vector3.UP)
print("Shot params: θ=%d φ=%d" % [rad_to_deg(elevation), rad_to_deg(azimuth)])
if elevation < -PI or elevation > PI:
print("wtf?? θ=%d" % rad_to_deg(elevation))
return
fire_direction = Vector3.FORWARD
fire_direction = fire_direction.rotated(Vector3(1,0,0), elevation)
fire_direction = fire_direction.rotated(Vector3(0,1,0), azimuth)
else:
fire_direction = (aim_target - bullet_pos).normalized()
DebugDraw3D.draw_arrow_ray(bullet_pos, fire_direction, target_range, Color.RED, 0.5, true, shot_time)
bullet.look_at(bullet_pos+fire_direction)
bullet.linear_velocity = (-bullet.global_basis.z) * shot_velocity
#bullet.apply_impulse((aim_target - bullet.global_position).normalized()*shot_impulse)
bullet.look_at(aim_target)
bullet.apply_impulse((aim_target - bullet.global_position).normalized()*shot_impulse)
bullet.angular_velocity = (bullet.global_basis * Vector3(0,0,-10))
current_target = null
ammo -= 1
if ammo <= 0:
Engine.time_scale = 1.0
loaded = LoadState.UNLOADED
func find_fire_angle(distance: float, height: float, high_solution: bool = true) -> float:
# theta = arctan( ( (v^2) ± sqrt( v^4 - g*( g*x^2 + 2*y*v^2 ) ) ) / g*x )
const g: float = 9.8
var gx2: float = g * pow(distance, 2)
var twoyv2: float = 2 * height * pow(shot_velocity,2)
var v2: float = pow(shot_velocity, 2)
var v4: float = pow(shot_velocity, 4)
var arc_x: float = g * distance
var arc_y_offs: float = sqrt(v4 - g * (gx2 + twoyv2))
var arc_y: float = v2 + arc_y_offs * (1 if high_solution else -1)
var theta: float = atan2(arc_y, arc_x)
return clamp(theta, -PI/2, PI/2)

View File

@ -1,15 +1,9 @@
extends RigidBody3D
class_name Unit
@export_group("Defence")
@export var max_hp: float = 100
@export_group("Movement")
@export var movement_force: float = 100
@export var rotation_torque: float = 3
@export var max_speed: float = 100
@export_group("Navigation")
@export var minimum_progress_rate: float = 1.0
@export var stuck_time: float = 1.0
@ -41,7 +35,6 @@ func _process(delta: float) -> void:
if nav_agent_3d.is_target_reached() \
or nav_agent_3d.target_position.is_zero_approx() \
or !nav_agent_3d.is_target_reachable():
#target_velocity = Vector3()
nav_agent_3d.target_position = move_target + Vector3(randfn(0, move_radius), 0, randfn(0, move_radius))
#nav_agent_3d.target_position = NavigationServer3D.map_get_random_point(NavigationServer3D.get_maps()[0], 1, true)
last_distance_to_target = nav_agent_3d.distance_to_target()
@ -63,11 +56,10 @@ func _process(delta: float) -> void:
var next_point: Vector3 = nav_agent_3d.get_next_path_position()
#DebugDraw3D.draw_sphere(next_point, 0.1, Color.YELLOW)
var direction: Vector3 = (next_point - global_position).normalized()
#basis = Basis.looking_at(direction)
#DebugDraw3D.draw_line(global_position, global_position + linear_velocity, Color.BLUE)
target_velocity = direction * max_speed
nav_agent_3d.velocity = target_velocity
#DebugDraw3D.draw_line(global_position, global_positiaon + target_velocity, Color.MAGENTA)
#DebugDraw3D.draw_line(global_position, global_position + target_velocity, Color.MAGENTA)
#DebugDraw3D.draw_text(global_position + Vector3(0,1,0), "%f" % nav_agent_3d.distance_to_target())
func unstuck() -> void:
@ -98,6 +90,3 @@ func _physics_process(delta: float) -> void:
var force: Vector3 = (force_direction * movement_force).slide(normal)
#DebugDraw3D.draw_line(global_position, global_position + force, Color.GREEN)
apply_central_force(force)
apply_torque(Vector3(0,force_direction.normalized().signed_angle_to(-global_basis.z, Vector3.DOWN) * rotation_torque,0))
#DebugDraw3D.draw_line(global_position, global_position - global_basis.z, Color.BLUE)
#DebugDraw3D.draw_line(global_position, global_position + force_direction, Color.RED)