Code: Select all
{
PosX [0]
PosY [0]
PosZ [0]
Dx [0]
Dy [0]
Dz [0]
Dx_hinge [0]
Dy_hinge [0]
Dz_hinge [0]
Dx_hinge2 [0]
Dy_hinge2 [0]
Dz_hinge2 [0]
Mass [1]
Scale [1]
ALPHA [255]
MyBodyId [-1]
SenId1 [-1]
RocketId [-1]
KeyReleased [true]
Depth [0.0]
TORQUE_REAR [0]
TORQUE_FRONT [0]
CODE [0]
Body
{
Body0 [0]
Body1 [0]
Body2 [0]
Body3 [0]
Body4 [0]
Body5 [0]
Body6 [0]
Body7 [0]
Body8 [0]
Body9 [0]
Body10 [0]
Body11 [0]
Body12 [0]
Body13 [0]
Body14 [0]
Body15 [0]
Body16 [0]
Body17 [0]
Body18 [0]
Body19 [0]
Body20 [0]
}
Init[ () //Is excecuted only once.
{
Console(true);
PosX = 0;
PosY = -340;
PosZ = 0;
DefineMaterial(1, 100, 0.5);
Body[0] = CreateRigidBody("Body0", "chassis.act",8,8,8, 255, PosX, PosY, PosZ, 0,0,0, 0,0,0 , true, ALPHA, "Box 133 40 74", 1, 0,0,0,0, Mass);
Dx = GetBodyBBox(Body[0], 0);
Dy = GetBodyBBox(Body[0], 1);
Dz = GetBodyBBox(Body[0], 2);
Dx_hinge = GetBodyBBox(Body[3], 0);
Dy_hinge = GetBodyBBox(Body[3], 1);
Dz_hinge = GetBodyBBox(Body[3], 2);
Body[1] = CreateRigidBody("Body1", "tyre.act", 8,8,8, 255, PosX+Dx*0.3, PosY-(Dy*0.45)-(Dy_hinge*0.35), PosZ+Dz*0.35,0,0,0, 0,0,0, true, ALPHA, "Sphere 0", 0, 0,0,0,0, Mass);
Body[2] = CreateRigidBody("Body2", "tyre.act", 8,8,8, 255, PosX+Dx*0.3, PosY-(Dy*0.45)-(Dy_hinge*0.35), PosZ-Dz*0.35,0,0,0, 0,0,0, true, ALPHA, "Sphere 0", 0, 0,0,0,0, Mass);
CreateHingeJoint(Body[0], Body[1], PosX+Dx*0.3, PosY-(Dy*0.45)-(Dy_hinge*0.35), PosZ+Dz*0.35, -180, 180, -180, 180, Dz*0.25, -1, 0, 0);
CreateHingeJoint(Body[0], Body[2], PosX+Dx*0.3, PosY-(Dy*0.45)-(Dy_hinge*0.35), PosZ-Dz*0.35, -180, 180, -180, 180, Dz*0.25, -1, 0, 0);
Body[3] = CreateRigidBody("Body3", "hinge6.act",2,2,2, 255, PosX-Dx*0.5, PosY-(Dy*0.45), PosZ+Dz*0.35, 0,0,0, 0,0,0, true, ALPHA, "Box 0", 0, 0,0,0,0, Mass);
CreateHingeJoint(Body[0], Body[3], PosX-Dx*0.5, PosY-(Dy*0.45)+Dy_hinge*0.8, PosZ+Dz*0.35, -180, 180, -180, 180, 0, -1, 0, 0);
CreateHingeJoint(Body[0], Body[3], PosX-Dx*0.5, PosY-(Dy*0.45)+Dy_hinge*0.2, PosZ+Dz*0.35, -180, 180, -180, 180, 0, -1, 0, 0);
Body[5] = CreateRigidBody("Body5", "tyre.act", 8,8,8, 255, PosX-(Dx*0.5), PosY-(Dy*0.45)-(Dy_hinge*0.35), PosZ+(Dz*0.35), 0,0,0, 0,0,0, true, ALPHA, "Sphere 0", 0, 0,0,0,0, Mass);
CreateHingeJoint(Body[3], Body[5], PosX-(Dx*0.5), PosY-(Dy*0.45)-(Dy_hinge*0.35), PosZ+(Dz*0.35), -180, 180, -180, 180, Dz*0.25, -1, 0, 0);
Body[4] = CreateRigidBody("Body4", "hinge6.act",2,2,2, 255, PosX-Dx*0.5, PosY-(Dy*0.45), PosZ-Dz*0.35, 0,0,0, 0,0,0, true, ALPHA, "Box 0", 0, 0,0,0,0, Mass);
CreateHingeJoint(Body[0], Body[4], PosX-Dx*0.5, PosY-(Dy*0.45)+Dy_hinge*0.8, PosZ-Dz*0.35, -180, 180, -180, 180, 0, -1, 0, 0);
CreateHingeJoint(Body[0], Body[4], PosX-Dx*0.5, PosY-(Dy*0.45)+Dy_hinge*0.2, PosZ-Dz*0.35, -180, 180, -180, 180, 0, -1, 0, 0);
Body[6] = CreateRigidBody("Body6", "tyre.act", 8,8,8, 255, PosX-(Dx*0.5), PosY-(Dy*0.45)-(Dy_hinge*0.35), PosZ-(Dz*0.35), 0,0,0, 0,0,0, true, ALPHA, "Sphere 0", 0, 0,0,0,0, Mass);
CreateHingeJoint(Body[4], Body[6], (PosX-Dx*0.5), PosY-(Dy*0.45)-(Dy_hinge*0.35), PosZ-(Dz*0.35), -180, 180, -180, 180, Dz*0.25, -1, 0, 0);
Dx_hinge2 = GetBodyBBox(Body[3], 0);
Dy_hinge2 = GetBodyBBox(Body[3], 1);
Dz_hinge2 = GetBodyBBox(Body[3], 2);
//Body[7] = CreateRigidBody("Body7", "box_centered.act", 0.5,0.5,3, 255, PosX-(Dx*0.3)-Dx_hinge2, PosY-(Dy*0.45)+Dy_hinge*0.5, PosZ, 0,0,0, 0,0,0, true, ALPHA, "Box 0", 0, 0,0,0,0, Mass);
//CreateHingeJoint(Body[3], Body[7], PosX-(Dx*0.3)-Dx_hinge2, PosY-(Dy*0.45)+Dy_hinge*0.5, PosZ, -180, 180, -180, 180, 10, -1, 0, 0);
//CreateHingeJoint(Body[4], Body[7], PosX-(Dx*0.3)-Dx_hinge2, PosY-(Dy*0.45)+Dy_hinge*0.5, PosZ, -180, 180, -180, 180, 10, -1, 0, 0);
//CreateHingeJoint(Body[3], Body[4], PosX-Dx*0.3+Dx_hinge2, PosY-(Dy*0.45)-(Dy_hinge*0.5), PosZ, -180, 180, -180, 180, (Dz*0.35)/2, -1, 0, 0);
//Body[6] = CreateRigidBody("Body6", "tyre.act", 8,8,8, 255, PosX-Dx*0.3, PosY-Dy*0.45, PosZ-Dz*0.35, 0,0,0, 0,0,0, true, ALPHA, "Sphere 0", 0, 0,0,0,0, Mass/4);
//SetBodyProperties(Body[3], true, 0.000005, 0.1, true);
//SetBodyProperties(Body[4], true, 0.000005, 0.1, true);
//CreateHingeJoint(Body[0], Body[6], PosX-Dx*0.3, PosY-Dy*0.45, PosZ-Dz*0.35, -180, 180, -180, 180, Dz*0.25, -1, 0, 0);
} ]
Start[ ()
{
Console(true);
ShowPhysicsBBox(false);
Dx = GetBodyBBox(Body[0], 0);
Dy = GetBodyBBox(Body[0], 1);
Dz = GetBodyBBox(Body[0], 2);
//SetTorque(Body[1], 0, 0, TORQUE_REAR, true);
//SetTorque(Body[2], 0, 0, TORQUE_REAR, true);
//ApplyTwist(Body[1], 0, 0, TORQUE_REAR, true);
//ApplyTwist(Body[2], 0, 0, TORQUE_REAR, true);
SetTorque(Body[5], 0, 0, TORQUE_REAR, true);
SetTorque(Body[6], 0, 0, TORQUE_REAR, true);
if(self.leftmousekey_pressed=true)
{
TORQUE_REAR=500;
}
else
{
if(self.rightmousekey_pressed)
{
TORQUE_REAR=-500;
}
else
{
TORQUE_REAR=0;
}
}
if(self.key_pressed=57)
{
//SetTorque(Body[3], 0, 400, 0, true);
//SetTorque(Body[4], 0, 400, 0, true);
//ApplyTwist(Body[3], 0, 4000, 0, true);
//ApplyTwist(Body[4], 0, 4000, 0, true);
TORQUE_FRONT=400;
}
else
{
if(self.key_pressed=58)
{
TORQUE_FRONT=-400;
//SetTorque(Body[3],0, -400, 0, true);
//SetTorque(Body[4],0, -400, 0, true);
}
else
{
TORQUE_FRONT=0;
}
}
ApplyTwist(Body[3], 0, TORQUE_FRONT, 0, true);
ApplyTwist(Body[4], 0, TORQUE_FRONT, 0, true);
if(self.key_pressed=46)
{
ApplyImpulse(Body[0], 0, 80, 0, true);
}
} ]
}
ok, scuse me nout, I don't want to spam you and all the community members, but this is one of the most funny game I ever played
It's like a MECCANO (I don't know the english name of that child construction game).
I've applied the previous vertical hinge double joint to the first car example. So here we are: a
. Naturally there are better ways to create a vehicle but the goal now is understand the physic scripting and then create some strange vehicle or mechanism (I've created a bike, if anyone is interested...).
The hinge car seems quite stable. I had to orient he joint backward because all the tries to restrict the motion have failed. Considered that the "normal" direction of a car is forward, the problems aren't so evident. One thing has to be said: this is a REAL physic. So the forward motion has the effect to force the wheel to mantain the correct orientation (wow!). So the hinges aren't constrained at all.
I placed one big yellow hinge so you can see and evaluate his work comparing to the previous example Hinge Demo 1.
If you want to change the Mass of the car you can do it in the declared variable at the beginning of the script: be careful, you will have to change the rotation force applied to the hinge steer (TORQUE_FRONT).
Only two oddity in the physic system. the first is that is relatively slow in the response. Many tester have seen this but something tell that nout hasn't a clear perception of ths. Second, To obtain a reasonable friction I had to put 100 in the physics script entity and in the material defined for the scripted bodies.
I also scripted a simple camera change to see clearly what happens.
Last Note: wait 1-2 seconds before apply forces. Otherwise doesn't work.
Now the car has a bug in the rotation that Nout has fixed. So if the car seems to break and float in the air, don't think about it... the new alpha is closer and closer.
a) Hinge Car: a car in a box...