From edf7f0668d282f64b5cea784cbeeb969864afa29 Mon Sep 17 00:00:00 2001 From: Ivan Yuriev Date: Mon, 7 Apr 2025 23:52:30 +0300 Subject: [PATCH] velocity-based rotation demo --- main.lua | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/main.lua b/main.lua index 5f6503e..cbc68fe 100644 --- a/main.lua +++ b/main.lua @@ -79,16 +79,20 @@ end local lastDir function love.update(dt) - local mouse = Vec3 { love.mouse.getPosition() } - if (mouse) then Fox:lookAt(mouse) end - + Fox.rotation = Fox.velocity:direction() if (lastDir and lastDir ~= Fox:namedDirection()) then + local t = Fox.sprite[Fox.sprite.playing].currentTime Fox.sprite.playing = "walk_" .. Fox:namedDirection() + Fox.sprite[Fox.sprite.playing].currentTime = t end lastDir = Fox:namedDirection() Player:update(dt) - Fox.position = Vec3 { Player.position().x, Player.position().y, 0 } + Fox.velocity = Vec3 { Player.velocity().x, Player.velocity().y, 0 } + + if Fox.velocity:length() < 0.1 then + Fox.sprite[Fox.sprite.playing].currentTime = 0 + end Fox:update(dt) end