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

View file

@ -18,6 +18,7 @@ const MORTAR_IDX := 2
static var instance: Player
@export var shake_noise: FastNoiseLite
@export var cannon: Node3D
var shake_duration := 0.
@onready var camera_transform: Transform3D = %Camera3D.transform
@ -44,6 +45,11 @@ var gun_index := 0:
var gun: Gun:
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:
instance = self
@ -62,7 +68,7 @@ func _process_movement(delta: float) -> void:
input.normalized()
var mul := 10. if DebugMenu.high_speed_hack else 1.
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()
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 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()
%Cannon.rotation.y = 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
func _process_shoot(delta: float) -> void:
@ -157,6 +164,24 @@ func _process(delta: float) -> void:
%MortarDecal.visible = gun_index == MORTAR_IDX
%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:
if health <= 0: return
if state == State.DASHING: