Files
game_engine/examples/survivor_game/src/projectile.rs
tolelom 5496525a7f feat(game): add projectile shooting toward mouse aim
Left click fires small yellow sphere projectiles from the player toward
the mouse cursor position on the XZ plane. Includes fire cooldown (0.2s),
projectile lifetime (2.0s), and ray-plane intersection for mouse aiming.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-25 17:35:46 +09:00

27 lines
547 B
Rust

use voltex_math::Vec3;
pub struct Projectile {
pub position: Vec3,
pub velocity: Vec3,
pub lifetime: f32,
}
impl Projectile {
pub fn new(origin: Vec3, direction: Vec3, speed: f32) -> Self {
Self {
position: origin,
velocity: direction * speed,
lifetime: 2.0,
}
}
pub fn update(&mut self, dt: f32) {
self.position = self.position + self.velocity * dt;
self.lifetime -= dt;
}
pub fn is_alive(&self) -> bool {
self.lifetime > 0.0
}
}