PDA

View Full Version : How to acheive weightlessness ???



Abened
13-11-2003, 06:12 PM
Hi everybody, i'm trying to make a space fighter move like it would do in space : when launched at a certain speed and a direction, it still goes straight when you stop accelerating... i'm sure you now what i mean :)

To do this i've tried to use a 3D vector to represent the position and the direction of the ship, and a single to represent the angle it's rotated (the game is in 2D so a single is enough to represent rotation).

What i'd like to know is how to modify direction when player accelerate but accordingly to the current angle of the ship.
Example : the player goes straight and the turn on hiself of 90AŹ? and then accelerate again, how to change his direction so it'll look "right" for the player...
I've hear a little about vectors and crossproduct and things like thant but i'm still very far away from the solution... please help if you dare !!! :twisted: (and if you understood my ugly english)

Abened

Paulius
13-11-2003, 06:35 PM
Easier coded then said in English:
SpeedX:= SpeedX + acceleration * cos(Angle);
SpeedY:= SpeedY + acceleration * sin(Angle);
ShipX := ShipX + SpeedX;
ShipY := ShipY + SpeedY;

WILL
13-11-2003, 07:18 PM
Ah... I see you have the math right, but how do you stop it from adding up so fast it goes zipping right off the map? :)

I've used a speed cap, but there obviously must be some better way...

Paulius
13-11-2003, 08:05 PM
I?˘_~m not sure I understood the question, you have to limit speed, we?˘_Tll you could do it in a nicer speed dependant way, like
AccX:= acceleration * cos(Angle);
AccY:= acceleration * sin(Angle);
XMul:= 1;
YMul:= 1;

If ((AccX>0)and(SpeedX>0) or (AccX<0)and(SpeedX<0)) then
begin
spd:= SpeedX;
if spd<0 then spd:=- spd;
XMul:= (MAX_SPEED ?˘_" spd)/ MAX_SPEED;
End;

If ((AccY>0)and(SpeedY>0) or (AccY<0)and(SpeedY<0)) then
begin
spd:= SpeedY;
if spd<0 then spd:=- spd;
YMul:= (MAX_SPEED ?˘_" spd)/ MAX_SPEED;
End;

SpeedX:= SpeedX + XMul * AccX;
SpeedY:= SpeedY + YMul * AccY;

Abened
13-11-2003, 08:53 PM
After some more brain use i found out quite the same solution as you posted ! :) Still, tanks alot for you're fast replies...
Abened