Asteroid Style Movement

Blitz3D Forums/Blitz3D Beginners Area/Asteroid Style Movement

Crazy4Code(Posted 2005) [#1]
I'll probably figure this out by myself by the time someone responds, but it never hurts to ask, i'm trying to figure out how to do a Asteroids style ship movement. So, it's not like it only moves when you tell it to, but the momentum stays and the ship keeps moving. Right now, the ship moves according to it's rotation angle, and the speed changes with the spacebar, but, for one thing, if you change direction, it goes that way. I want it to keep going the direction it was going until you hit the spacebar and change direction. Am I making any sense? And also, I want it to change depending on which direction your facing. So, if you're going up, and then you turn around and turn on the engines, you should start going that way. Sorry, I didn't explain that very well, but just play asteroids online and you'll know what I mean.


octothorpe(Posted 2005) [#2]
Use separate variables (vx# and vy#) for keeping track of the player's velocity. While the player accellerates, add a small amount to them (vx=vx+sin(dir)*speed:vy=vy+cos(dir)*speed). Every update, add the velocity to the position (x=x+vx:y=y+vy). Thusly, the player has control over his accelleration, but not his position (unless he engages his emergency random teleport device, which I believe all asteroids ships are equipped with during factory assembly.)

If you decide that there's air in space, you can multiply the velocity by a number close to 1 (try .9) to decay the velocity and achieve drag.

Happy hunting!


tonyg(Posted 2005) [#3]
These might help...
Space Physics tutorial
ASteroids lib
basic asteroids example


Crazy4Code(Posted 2005) [#4]
Thanks, I almost had that :)


Crazy4Code(Posted 2005) [#5]
I did what you said octothorpe, and it works, except that it accelerates WAY too fast. I think it's the same problem I having in my Turrets thread, where I can't figure out how to move in fractions. What should I do?


Crazy4Code(Posted 2005) [#6]
Oh nevermind, I got it!