Archived

This topic is now archived and is closed to further replies.

Bluehair

Normalising Speed

Recommended Posts

Hi, I am trying to make a ship continually fly at a setspeed, however I have managed to get it to accelerate but when it reaches the set speed inertia no longer takes effect allowing it to turn without any impact on speed. Im not very good at maths so I dont have any idea of where to go from here, I have tried searching the web but couldnt find anything to help. I am programming in Blitz Basic, which uses degrees instead of radians, if that helps at all. Ive included the inertia below, Player_Distance_2D() finds the dPlayer_ActualSpeed: Player_Distance_2D() ;Add/Sub Thrust to match set speed If dPlayer_ActualSpeed < dPlayer_SetSpeed dPlayerX_vel = dPlayerX_vel + (dPlayer_Thrust*Sin_Table(iPlayer_ShipDir*10)) ;10 from 360/Num of rotations for object dPlayerY_vel = dPlayerY_vel + (dPlayer_Thrust*Cos_Table(iPlayer_ShipDir*10)) ElseIf dPlayer_ActualSpeed > dPlayer_SetSpeed dPlayerX_vel = dPlayerX_vel - (dPlayer_Brake*Sin_Table(iPlayer_ShipDir*10)) ;10 from 360/Num of rotations for object dPlayerY_vel = dPlayerY_vel - (dPlayer_Brake*Cos_Table(iPlayer_ShipDir*10)) EndIf Player_Distance_2D() ;Stop from going too fast If dPlayer_ActualSpeed >= dPlayer_SetSpeed ;Pilot\dSetSpeed = Pilot\dTopSpeed ;Recompute velocity by normalising then rescaling dPlayerX_vel = (dPlayer_SetSpeed*Sin_Table(iPlayer_ShipDir*10)) ;10 from 360/Num of rotations for object dPlayerY_vel = (dPlayer_SetSpeed*Cos_Table(iPlayer_ShipDir*10)) EndIf ;Update x and y positions dPlayer_X = dPlayer_X + dPlayerX_vel dPlayer_Y = dPlayer_Y - dPlayerY_vel

Share this post


Link to post
Share on other sites