player tank model

This commit is contained in:
Michael Campbell 2026-04-01 13:06:27 -04:00
parent d63b6a5663
commit dc88120ff8
13 changed files with 215 additions and 21 deletions

BIN
.blender/tank.blend Normal file

Binary file not shown.

BIN
.blender/tank.blend1 Normal file

Binary file not shown.

View file

@ -3,6 +3,7 @@ extends Node3D
var boxes: Array[CSGBox3D] var boxes: Array[CSGBox3D]
var points: Array[Vector3] var points: Array[Vector3]
const MAX_ENEMIES := 30
const MAX_CACHED_POINTS := 100 const MAX_CACHED_POINTS := 100
var doomed_point_idx := 0 var doomed_point_idx := 0
@ -11,6 +12,8 @@ var weights: Array[float]
var total_cost := 0. var total_cost := 0.
var money := 5. var money := 5.
var total_enemies := 0
var rng := RandomNumberGenerator.new() var rng := RandomNumberGenerator.new()
func _get_point() -> Vector3: func _get_point() -> Vector3:

BIN
models/tank.glb Normal file

Binary file not shown.

42
models/tank.glb.import Normal file
View file

@ -0,0 +1,42 @@
[remap]
importer="scene"
importer_version=1
type="PackedScene"
uid="uid://54f44t3gniw2"
path="res://.godot/imported/tank.glb-3907167ee0d98c32d67c9e3b5542cdd3.scn"
[deps]
source_file="res://models/tank.glb"
dest_files=["res://.godot/imported/tank.glb-3907167ee0d98c32d67c9e3b5542cdd3.scn"]
[params]
nodes/root_type=""
nodes/root_name=""
nodes/root_script=null
nodes/apply_root_scale=true
nodes/root_scale=1.0
nodes/import_as_skeleton_bones=false
nodes/use_name_suffixes=true
nodes/use_node_type_suffixes=true
meshes/ensure_tangents=true
meshes/generate_lods=true
meshes/create_shadow_meshes=true
meshes/light_baking=1
meshes/lightmap_texel_size=0.2
meshes/force_disable_compression=false
skins/use_named_skins=true
animation/import=true
animation/fps=30
animation/trimming=false
animation/remove_immutable_tracks=true
animation/import_rest_as_RESET=false
import_script/path=""
materials/extract=0
materials/extract_format=0
materials/extract_path=""
_subresources={}
gltf/naming_version=2
gltf/embedded_image_handling=1

BIN
models/tank_Untitled.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 127 KiB

View file

@ -0,0 +1,44 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://c3558cp5qqb2t"
path.s3tc="res://.godot/imported/tank_Untitled.png-7c9d9b048ab151d1bd129f409533fdda.s3tc.ctex"
metadata={
"imported_formats": ["s3tc_bptc"],
"vram_texture": true
}
generator_parameters={
"md5": "f494a15d45f8af8872c3bef56ef93744"
}
[deps]
source_file="res://models/tank_Untitled.png"
dest_files=["res://.godot/imported/tank_Untitled.png-7c9d9b048ab151d1bd129f409533fdda.s3tc.ctex"]
[params]
compress/mode=2
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=true
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
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

BIN
models/tank_Untitled_1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 140 KiB

View file

@ -0,0 +1,44 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://qnwpvm1hx8p4"
path.s3tc="res://.godot/imported/tank_Untitled_1.png-d7b40899902a4db16432bc0141be7a85.s3tc.ctex"
metadata={
"imported_formats": ["s3tc_bptc"],
"vram_texture": true
}
generator_parameters={
"md5": "c48dd504d1079dbf1ff534515af74348"
}
[deps]
source_file="res://models/tank_Untitled_1.png"
dest_files=["res://.godot/imported/tank_Untitled_1.png-d7b40899902a4db16432bc0141be7a85.s3tc.ctex"]
[params]
compress/mode=2
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=true
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
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

BIN
models/tank_Untitled_2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 KiB

View file

@ -0,0 +1,44 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://ctcllt5wc0urr"
path.s3tc="res://.godot/imported/tank_Untitled_2.png-7f4a2b559c3c0d49551b21471cfe6ea3.s3tc.ctex"
metadata={
"imported_formats": ["s3tc_bptc"],
"vram_texture": true
}
generator_parameters={
"md5": "6863b39f8e7c50e0200f2e2d1e249f1b"
}
[deps]
source_file="res://models/tank_Untitled_2.png"
dest_files=["res://.godot/imported/tank_Untitled_2.png-7f4a2b559c3c0d49551b21471cfe6ea3.s3tc.ctex"]
[params]
compress/mode=2
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=true
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
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

View file

@ -18,6 +18,7 @@ const MORTAR_IDX := 2
static var instance: Player static var instance: Player
@export var shake_noise: FastNoiseLite @export var shake_noise: FastNoiseLite
@export var cannon: Node3D
var shake_duration := 0. var shake_duration := 0.
@onready var camera_transform: Transform3D = %Camera3D.transform @onready var camera_transform: Transform3D = %Camera3D.transform
@ -44,6 +45,11 @@ var gun_index := 0:
var gun: Gun: var gun: Gun:
get: return guns[gun_index] get: return guns[gun_index]
func clean_angle(theta: float) -> float:
theta = fposmod(theta, TAU)
if theta < PI: return theta
else: return PI - theta
func _init() -> void: func _init() -> void:
instance = self instance = self
@ -62,7 +68,7 @@ func _process_movement(delta: float) -> void:
input.normalized() input.normalized()
var mul := 10. if DebugMenu.high_speed_hack else 1. var mul := 10. if DebugMenu.high_speed_hack else 1.
var desired_velocity = Vector3(input.x, 0., input.y) * MOVE_SPEED * mul * speed_mul var desired_velocity = Vector3(input.x, 0., input.y) * MOVE_SPEED * mul * speed_mul
velocity = exp_lerp(velocity, desired_velocity, 20, delta) velocity = exp_lerp(velocity, desired_velocity, 5, delta)
move_and_slide() move_and_slide()
if Input.is_action_just_pressed("dash") and stamina >= DASH_COST and not input.is_zero_approx(): if Input.is_action_just_pressed("dash") and stamina >= DASH_COST and not input.is_zero_approx():
@ -89,12 +95,13 @@ func _process_aim() -> void:
var t := -r_origin.y / r_dir.y var t := -r_origin.y / r_dir.y
var world_mouse_pos = r_origin + r_dir * t var world_mouse_pos = r_origin + r_dir * t
var to_mouse_pos = world_mouse_pos - global_position var to_mouse_pos = to_local(world_mouse_pos)
var angle = Vector2(to_mouse_pos.x, -to_mouse_pos.z).angle() var angle = Vector2(to_mouse_pos.x, -to_mouse_pos.z).angle()
%Cannon.rotation.y = angle
aim_angle = angle aim_angle = angle
var cannon_to_mouse_pos = cannon.get_parent().to_local(world_mouse_pos)
cannon.rotation.y = Vector2(cannon_to_mouse_pos.x, -cannon_to_mouse_pos.z).angle() + PI / 2
%Reticle.position = to_mouse_pos %Reticle.position = to_mouse_pos
func _process_shoot(delta: float) -> void: func _process_shoot(delta: float) -> void:
@ -157,6 +164,24 @@ func _process(delta: float) -> void:
%MortarDecal.visible = gun_index == MORTAR_IDX %MortarDecal.visible = gun_index == MORTAR_IDX
%MortarDecal.global_position = %Reticle.global_position %MortarDecal.global_position = %Reticle.global_position
var facing_dir := Vector2.RIGHT.rotated(%Tank.rotation.y)
var new_dir := Vector2(velocity.x, -velocity.z).rotated(PI / 2)
var opp_dir := new_dir.rotated(PI)
var new_dot = facing_dir.dot(new_dir)
var opp_dot = facing_dir.dot(opp_dir)
if new_dot > opp_dot:
%Tank.rotation.y = new_dir.angle()
else:
%Tank.rotation.y = opp_dir.angle()
# print("tank_angle = ", %Tank.rotation.y, "; angle = ", angle, "; angle2 = ", angle2)
# if (abs(angle - %Tank.rotation.y) <= abs(angle2 - %Tank.rotation.y)):
# %Tank.rotation.y = angle
# else:
# %Tank.rotation.y = angle2
func damage(damager: Node3D) -> void: func damage(damager: Node3D) -> void:
if health <= 0: return if health <= 0: return
if state == State.DASHING: if state == State.DASHING:

View file

@ -9,16 +9,12 @@
[ext_resource type="Script" uid="uid://urxp3pg8g2mh" path="res://player/health_bar.gd" id="7_boad6"] [ext_resource type="Script" uid="uid://urxp3pg8g2mh" path="res://player/health_bar.gd" id="7_boad6"]
[ext_resource type="Shader" uid="uid://cf3h3knluytmm" path="res://player/hp_outline.gdshader" id="8_rgyib"] [ext_resource type="Shader" uid="uid://cf3h3knluytmm" path="res://player/hp_outline.gdshader" id="8_rgyib"]
[ext_resource type="Script" uid="uid://ban0rphntn10r" path="res://player/stamina_bar.gd" id="9_hg6s5"] [ext_resource type="Script" uid="uid://ban0rphntn10r" path="res://player/stamina_bar.gd" id="9_hg6s5"]
[ext_resource type="PackedScene" uid="uid://54f44t3gniw2" path="res://models/tank.glb" id="10_8t03j"]
[sub_resource type="FastNoiseLite" id="FastNoiseLite_onrkg"] [sub_resource type="FastNoiseLite" id="FastNoiseLite_onrkg"]
[sub_resource type="BoxMesh" id="BoxMesh_onrkg"]
[sub_resource type="BoxShape3D" id="BoxShape3D_i3pqv"] [sub_resource type="BoxShape3D" id="BoxShape3D_i3pqv"]
[sub_resource type="BoxMesh" id="BoxMesh_hqtel"]
size = Vector3(2, 0.1, 0.1)
[sub_resource type="SphereMesh" id="SphereMesh_4flbx"] [sub_resource type="SphereMesh" id="SphereMesh_4flbx"]
[sub_resource type="ViewportTexture" id="ViewportTexture_g6k8r"] [sub_resource type="ViewportTexture" id="ViewportTexture_g6k8r"]
@ -44,17 +40,14 @@ height = 256
fill = 1 fill = 1
fill_from = Vector2(0.5, 0.5) fill_from = Vector2(0.5, 0.5)
[node name="Player" type="CharacterBody3D" unique_id=1904432250 node_paths=PackedStringArray("guns")] [node name="Player" type="CharacterBody3D" unique_id=1904432250 node_paths=PackedStringArray("cannon", "guns")]
collision_layer = 2 collision_layer = 2
collision_mask = 13 collision_mask = 13
script = ExtResource("1_4flbx") script = ExtResource("1_4flbx")
shake_noise = SubResource("FastNoiseLite_onrkg") shake_noise = SubResource("FastNoiseLite_onrkg")
cannon = NodePath("Tank/Turret")
guns = [NodePath("Guns/Sharpshooter"), NodePath("Guns/MiniGun"), NodePath("Guns/Mortar")] guns = [NodePath("Guns/Sharpshooter"), NodePath("Guns/MiniGun"), NodePath("Guns/Mortar")]
[node name="MeshInstance3D" type="MeshInstance3D" parent="." unique_id=204505475]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0)
mesh = SubResource("BoxMesh_onrkg")
[node name="CollisionShape3D" type="CollisionShape3D" parent="." unique_id=918462062] [node name="CollisionShape3D" type="CollisionShape3D" parent="." unique_id=918462062]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0)
shape = SubResource("BoxShape3D_i3pqv") shape = SubResource("BoxShape3D_i3pqv")
@ -63,13 +56,6 @@ shape = SubResource("BoxShape3D_i3pqv")
unique_name_in_owner = true unique_name_in_owner = true
transform = Transform3D(1, 0, 0, 0, 0.53349644, 0.84580237, 0, -0.84580237, 0.53349644, 0, 20.150661, 11.874705) transform = Transform3D(1, 0, 0, 0, 0.53349644, 0.84580237, 0, -0.84580237, 0.53349644, 0, 20.150661, 11.874705)
[node name="Cannon" type="Node3D" parent="." unique_id=985210791]
unique_name_in_owner = true
[node name="MeshInstance3D" type="MeshInstance3D" parent="Cannon" unique_id=1149215568]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0.75, 0)
mesh = SubResource("BoxMesh_hqtel")
[node name="Reticle" type="MeshInstance3D" parent="." unique_id=242722222] [node name="Reticle" type="MeshInstance3D" parent="." unique_id=242722222]
unique_name_in_owner = true unique_name_in_owner = true
visible = false visible = false
@ -270,3 +256,9 @@ size = Vector3(6.55249, 50.942444, 6.388672)
texture_albedo = SubResource("GradientTexture2D_8t03j") texture_albedo = SubResource("GradientTexture2D_8t03j")
modulate = Color(0.89, 0.40049997, 0.40049997, 1) modulate = Color(0.89, 0.40049997, 0.40049997, 1)
cull_mask = 1 cull_mask = 1
[node name="Tank" parent="." unique_id=1376341535 instance=ExtResource("10_8t03j")]
unique_name_in_owner = true
transform = Transform3D(-0.6377325, 0, -5.5752345e-08, 0, 0.6377325, 0, 5.5752345e-08, 0, -0.6377325, 0, 0.75759906, 0)
[editable path="Tank"]