i had found on this site
http://gamedev.stackexchange.com/questi ... -dimension
a simple looking carphysik.
now after implement it , my car move without do something ^^
perhaps somebody see my mistake thanks for help.
code from site:
Code: Select all
Vector2 position;
Vector2 frontTire, backTire;
float direction;
float speed;
float angle;
float wheelBase = 32;
frontTire = position + wheelBase / 2 * new Vector2((float)Math.Cos(direction), (float)Math.Sin(direction));
backTire = position - wheelBase / 2 * new Vector2((float)Math.Cos(direction), (float)Math.Sin(direction));
backTire += speed * elapsed * new Vector2((float)Math.Cos(direction), (float)Math.Sin(direction));
frontTire += speed * elapsed * new Vector2((float)Math.Cos(direction + angle), (float)Math.Sin(direction + angle));
position = (frontTire + backTire) / 2;
direction = (float)Math.Atan2(frontTire.Y - backTire.Y, frontTire.X - backTire.X);
Code: Select all
Structure Vector
X.f
Y.f
EndStructure
Structure Car
Position.Vector
frontTire.Vector
backTire.Vector
speed.f
angle.f
wheelbase.f
direction.f
EndStructure
Procedure.i V_Add(*Use.Vector, *Source.Vector, Factor.VT=1.0)
*Use\X + *Source\X*Factor
*Use\Y + *Source\Y*Factor
ProcedureReturn *Use
EndProcedure
Procedure.i V_Divide(*Use.Vector, Value.VT)
*Use\X / Value
*Use\Y / Value
ProcedureReturn *Use
EndProcedure
Procedure.f gSin(Ang.f)
ProcedureReturn Sin(Radian(Ang))
EndProcedure
Procedure.f gCos(Ang.f)
ProcedureReturn Cos(Radian(Ang))
EndProcedure
;//frontTire = position + wheelBase / 2 * new Vector2((float)Math.Cos(direction), (float)Math.Sin(direction));
PlayerCar()\frontTire\x = PlayerCar()\Position\X + PlayerCar()\wheelbase /2 * gCos(PlayerCar()\direction)
PlayerCar()\frontTire\y = PlayerCar()\Position\Y + PlayerCar()\wheelbase /2 * gSin(PlayerCar()\direction)
;//backTire = position - wheelBase / 2 * new Vector2((float)Math.Cos(direction), (float)Math.Sin(direction));
PlayerCar()\backTire\x = PlayerCar()\Position\X - PlayerCar()\wheelbase /2 * gCos(PlayerCar()\direction)
PlayerCar()\backTire\y = PlayerCar()\Position\Y - PlayerCar()\wheelbase /2 * gSin(PlayerCar()\direction)
;//backTire += speed * elapsed * new Vector2((float)Math.Cos(direction), (float)Math.Sin(direction));
PlayerCar()\backTire\X + PlayerCar()\speed * elapsed * gCos(PlayerCar()\direction)
PlayerCar()\backTire\Y + PlayerCar()\speed * elapsed * gSin(PlayerCar()\direction)
;//frontTire += speed * elapsed * new Vector2((float)Math.Cos(direction + angle), (float)Math.Sin(direction + angle));
PlayerCar()\frontTire\X + PlayerCar()\speed * elapsed * gCos(PlayerCar()\direction + PlayerCar()\angle)
PlayerCar()\frontTire\Y + PlayerCar()\speed * elapsed * gSin(PlayerCar()\direction + PlayerCar()\angle)
;// position = (frontTire + backTire) / 2;
V_Add(PlayerCar()\Position,V_Division(PlayerCar()\Position,V_Add(PlayerCar()\frontTire,PlayerCar()\backTire),2))
;direction = (float)Math.Atan2(frontTire.Y - backTire.Y, frontTire.X - backTire.X);
PlayerCar()\direction = ATan2(PlayerCar()\frontTire\Y - PlayerCar()\backTire\Y,PlayerCar()\frontTire\x - PlayerCar()\backTire\x)
Code: Select all
[13:38:35] speed0
[13:38:35] direction0
[13:38:35] angle0
[13:38:35] frontTire0
[13:38:35] frontTire0
[13:38:35] backTire0
[13:38:35] backTire0
[13:38:35] Position512
[13:38:35] Position400
[13:38:35] speed0
[13:38:35] direction0.9149441719
[13:38:35] angle0
[13:38:35] frontTire2048
[13:38:35] frontTire1600
[13:38:35] backTire1008.0020751953
[13:38:35] backTire799.7424316406
[13:38:35] Position2048
[13:38:35] Position1600