Again, I'm making an arcade game, a little bit like galaga and space invaders, but I want my ship to move like the one in asteroids. I'm tired of having it move twip by twip. What kind of coding will allow me to do this?
Printable View
Again, I'm making an arcade game, a little bit like galaga and space invaders, but I want my ship to move like the one in asteroids. I'm tired of having it move twip by twip. What kind of coding will allow me to do this?
So you want the ship to rotate, with a thrust, right?
I dunno what you are doing this in, but in asteroids, your are in space so it is as easy as.
Vd = Vu + (Va * t)
VPos = VPos + Vd
Or, The Displacement is equal to the initial velocity plus the acceleration of the object multiplied by the time of movement.
Then add the displament to the pos.
They are all vectors except t, t is the time that has passed since the last frame, or the last time the unit routine was checked.
Va may be tough to determine at first, but lets say you want an acceleration 45 degree down the x,z travelling 5km
Va.X = cos(45)
Va.Z = sin(45)
Va = Va * 5
Of course 45 must be converted to RAD before used with most cos and sin functions. Once you multiply by 5 you will have a unit vector 5 steps down 45 degree, so any unit using that will accelerate at a rate of 5 units (units can be anything you specify, so in this example we are in KM).
To convert it to radians you do this:
VB Code:
Va.X = cos(45 [b]* PI / 180[/b]) Va.Z = sin(45 [b]* PI / 180[/b]) Va = Va * 5
Where PI = 3.141592654
In bold is the area that converts it. So the formula is basically Angle * PI / 180 :bigyello:
I didn't intend for it to rotate. But I just want the movement. Like when you would make it move right,by pressing the button once, it would move but very slowly. And if you were to hit it multiple times, or hold the button, it would go faster. Ya know? The asteroid ship movement, just kinda floats when you make it move a certain direction.
We gave you all you need to know to accomplish that.
Think about it.
Ok well, i got it. I just dim avariable as single, then made x = x + or - 5 and the same with horizontal controls.
Think of the basic properties of physics, acceleration, velocity, and position. When you isolate these things everything will come easier. Then you don't ever have to do anything complicated, just integration over time.