add projectile model and material

This commit is contained in:
2025-07-04 04:54:04 +10:00
parent 6441ee8a68
commit 0589d4d253
13 changed files with 275 additions and 14 deletions

View File

@@ -2,23 +2,34 @@ class_name Projectile
extends Area3D
const HEIGHT: float = 1
const MAX_STRETCH: float = 0.75
@export var _speed_stretch_factor: float = 100
@export var _collision_debug_material: Material
var _start_position: Vector3
var _velocity: Vector3
var _lifetime: float
var _size: float = 0.25
var _life_timer: float
var _debug_collision_shapes := DebugCollisionShapes.new()
@onready var _model_base: Node3D = $Model
@onready var _model_mesh: MeshInstance3D = $Model/ProjectileMesh
func _ready() -> void:
_life_timer = _lifetime
_debug_collision_shapes.init(get_children(), self, _collision_debug_material)
global_position = _start_position
body_entered.connect(_on_body_entered)
_model_mesh.rotation = Vector3(
randf_range(0, TAU), randf_range(0, TAU), randf_range(0, TAU)
)
_model_mesh.scale = Vector3.ONE * _size
func _physics_process(delta: float) -> void:
@@ -27,6 +38,14 @@ func _physics_process(delta: float) -> void:
_life_timer -= delta
global_position += _velocity * delta
look_at(global_position + _velocity, Vector3.UP, true)
var speed_squash := clampf(
_velocity.length() / _speed_stretch_factor, 0, MAX_STRETCH
)
_model_base.scale = Vector3(
1 - speed_squash, 1 - speed_squash, 1 + speed_squash
)
func init(velocity: Vector3, start_position: Vector3, lifetime: float = 10) -> void: