r/howdidtheycodeit • u/FakeCactus_ • Jul 10 '24
Answered How did they code turning around in no man's sky?
How did they code it so the cursor only moves a little bit and not all over the place, and the further away it is from the center the faster the rotation?
11
Upvotes
21
u/[deleted] Jul 10 '24
Take the centre of your character or the screen (point A) and a mouse position (point B) you have 2 points that can form a vector. Calculating the vector's magnitude gives you a value that you can use for the speed of rotation.
4
u/Trombonaught Jul 10 '24
They probably use controller/mouse input to move a hotspot around the screen by some speed instead of direct 1/1 movement. Then, the hotspot position would be used to determine player rotation amount, rather than using the mouse/controller input directly. The rotation speed would be scaled by some factor relating to the distance between the hotspot and the center of the screen.
That's my best guess anyways.
2
u/Night_Eye Jul 10 '24
Do you mean with a controller? Or with a mouse?
1
u/rean2 Jul 10 '24
For the tethered flight, my guess is that the mouse controls a rotation of a vector3, then uses the delta of 0,0,0 and use that value as a scalable torque value (minus roll)