data endpoint for entity 90008 (aka. a website)
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: make it so pet can be thrown more intuitively

dusk e248213c 0fec463a

+28 -11
+28 -11
src/components/pet.svelte
··· 1 1 <script lang="ts"> 2 2 import { draggable } from '@neodrag/svelte'; 3 3 4 + let lastDragged = 0; 5 + let mouseX = 0; 6 + let mouseY = 0; 7 + 4 8 let position = $state({ x: 0, y: 0 }); 5 9 let rotation = $state(0.0); 6 10 let sprite = $state('/pet/idle.webp'); ··· 24 28 } 25 29 }; 26 30 27 - let targetRotation = $state(0.0); 28 - let rotationVelocity = $state(0.0); 31 + let targetRotation = 0.0; 32 + let rotationVelocity = 0.0; 29 33 let springStiffness = 20.0; // How quickly rotation returns to target 30 34 let springDamping = 0.2; // Damping factor to prevent oscillation 31 35 ··· 58 62 }; 59 63 60 64 // Physics constants 61 - let velocityX = $state(0); 62 - let velocityY = $state(0); 65 + let velocityX = 0; 66 + let velocityY = 0; 63 67 let gravity = 200.0; // Gravity strength (positive because -Y is up) 64 68 let friction = 0.96; // Air friction 65 69 let bounciness = 0.8; // How much energy is preserved on bounce ··· 99 103 position.y = 0; 100 104 velocityY = -velocityY * bounciness; 101 105 // Only bounce if velocity is significant 102 - if (Math.abs(velocityY) < 1) { 106 + if (Math.abs(velocityY) < 5) { 103 107 velocityY = 0; 104 108 position.y = 0; 105 109 } 106 110 } 107 111 108 - // Stop very small movements 109 - if (position.y === 0) { 112 + // reset velocity 113 + if (Math.abs(velocityX) < 5 && Math.abs(velocityY) < 5) { 110 114 velocityX = 0; 111 115 velocityY = 0; 112 - position.y = 0; 113 116 } 114 117 115 118 // Update flip based on velocity ··· 171 174 onDrag: ({ offsetX, offsetY, event }) => { 172 175 position.x = offsetX; 173 176 position.y = offsetY; 174 - rotationVelocity += event.movementY * delta + event.movementX * delta; 177 + const mouseXD = event.movementX * delta; 178 + const mouseYD = event.movementY * delta; 179 + // reset mouse movement if it's not moving in the same direction so it doesnt accumulate its weird!@!@ 180 + mouseX = Math.sign(mouseXD) != Math.sign(mouseX) ? mouseXD : mouseX + mouseXD; 181 + mouseY = Math.sign(mouseYD) != Math.sign(mouseY) ? mouseYD : mouseY + mouseYD; 182 + rotationVelocity += mouseXD + mouseYD; 183 + lastDragged = Date.now(); 175 184 }, 176 185 onDragEnd: () => { 177 186 dragged = false; 187 + // reset mouse movement if we stopped for longer than some time 188 + if (Date.now() - lastDragged > 50) { 189 + mouseX = 0.0; 190 + mouseY = 0.0; 191 + } 178 192 // apply velocity based on rotation since we already keep track of that 179 - velocityX = rotationVelocity * 80.0; 180 - velocityY = -Math.abs(rotationVelocity) * 30.0; 193 + velocityX = mouseX * 70.0; 194 + velocityY = mouseY * 50.0; 195 + // reset mouse movement we dont want it to accumulate 196 + mouseX = 0.0; 197 + mouseY = 0.0; 181 198 } 182 199 }} 183 200 class="absolute bottom-[5vh] z-[1000] hover:animate-squiggle"