It's a top down space ship, in zero gravity, and I'm applying forces to allow the ship to move and turn.
Each time a force is applied, it seems to be stronger than the last, causing the ship to become uncontrollable very quickly.
I'm resetting the forces after each step.
My forces for the UP arrow and DOWN arrow are as follows...
UP
Code: Select all
cpVect j = Ship.Body->rot
cpVect r = cpvzero
cpBodyApplyImpulse( Ship.Body, j, r )
Code: Select all
cpVect j = -Ship.Body->rot
cpVect r = cpvzero
cpBodyApplyImpulse( Ship.Body, j, r )
Note: I've added in some operands like + - * so I no longer need to use the cpvmult,add,sub functions etc
LEFT
Code: Select all
cpVect j = cpvperp( -Ship.Body->rot ) * 0.1
cpVect r = cpvrotate( cpv( 10.0, 0.0 ), Ship.Body->rot )
cpBodyApplyImpulse( Ship.Body, j, r )
j = cpvperp( Ship.Body->rot ) * 0.1
r = cpvrotate( cpv( -10.0, 0.0 ), Ship.Body->rot )
cpBodyApplyImpulse( Ship.Body, j, r )
RIGHT
Code: Select all
cpVect j = cpvperp( Ship.Body->rot ) * 0.1
cpVect r = cpvrotate( cpv( 10.0, 0.0 ), Ship.Body->rot )
cpBodyApplyImpulse( Ship.Body, j, r )
j = cpvperp( -Ship.Body->rot ) * 0.1
r = cpvrotate( cpv( -10.0, 0.0 ), Ship.Body->rot )
cpBodyApplyImpulse( Ship.Body, j, r )
If I press LEFT or RIGHT just once, it starts rotating, but continues to increase the rotation speed even after reseting the forces.
Any ideas?