RF and physics

Programming Reality Factory and Genesis3D.
User avatar
federico
RF Dev Team
Posts: 443
Joined: Tue Jul 05, 2005 3:14 pm
Contact:

Post by federico »

I've modified your script and prepared a model to test the scripts. Look at this:

Code: Select all

{

PosX [0]
PosY [0]
PosZ [0]
Dx [0]
Dy [0]
Dz [0]
Mass [1]
Scale [1]
ALPHA [255]
MyBodyId [-1]
SenId1 [-1]
RocketId [-1]
KeyReleased [true]
Depth [0.0]
TORQUE_REAR [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, 10, 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/4);
Dx = GetBodyBBox(Body[0], 0);
Dy = GetBodyBBox(Body[0], 1);
Dz = GetBodyBBox(Body[0], 2);

Body[1] = CreateRigidBody("Body1", "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);
Body[2] = CreateRigidBody("Body1", "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);
Body[3] = CreateRigidBody("Body1", "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);
Body[4] = CreateRigidBody("Body1", "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);
CreateHingeJoint(Body[0], Body[1], PosX+Dx*0.3, PosY-Dy*0.45, 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, PosZ-Dz*0.35, -180, 180, -180, 180, Dz*0.25, -1, 0, 0);
CreateHingeJoint(Body[0], Body[3], PosX-Dx*0.3, PosY-Dy*0.45, PosZ+Dz*0.35, -180, 180, -180, 180, Dz*0.25, -1, 0, 0);
CreateHingeJoint(Body[0], Body[4], 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);
debug(self.leftmousekey_pressed);
debug(TORQUE_REAR);

Dx = GetBodyBBox(Body[0], 0);
Dy = GetBodyBBox(Body[0], 1);
Dz = GetBodyBBox(Body[0], 2);
debug(Dx);
debug(Dy);
debug(Dz);

//SetTorque(Body[1], 0, 0, TORQUE_REAR, true); 
//SetTorque(Body[2], 0, 0, TORQUE_REAR, true); 
SetTorque(Body[3], 0, 0, TORQUE_REAR, true); 
SetTorque(Body[4], 0, 0, TORQUE_REAR, true); 

if(self.leftmousekey_pressed=true)
{
TORQUE_REAR=TORQUE_REAR+10;
}
else
{
TORQUE_REAR=TORQUE_REAR-40;
}



if(self.rightmousekey_pressed)
{
SetTorque(Body[3], 0, 0, 0, true); 
SetTorque(Body[4], 0, 0, 0, true); 
}
else
{
        if(TORQUE_REAR<=0)
        {
        TORQUE_REAR=0;
        }
        if(TORQUE_REAR>500)
        {
        TORQUE_REAR=500;
        }
}

} ]

}
I think to have understood the basic of the hinge joint. Thanks Nout.

Here, there is the download of two mini-demo that use this script.
http://realityfactory.altervista.org/do ... r_test.zip

1) Down the Hill. Look the car go down accordingly with the gravity force (no torque on wheels) to see how the hinge joint works. THE WHEELS ROTATE!

2) Car_Test. "LeftClick" to apply a torque on the front wheels. Any idea on how to turn the wheels in the examples, Nout, and make it work like a real car? This is the main question of my previous posts.

The car chassis has a buggy rotation problems. Are these the Y-Axis rotation problems that you solved in the next release? Does the physic development proceed in the desired way? Are you plannig an upgrade (exe + headers)?

Download: http://realityfactory.altervista.org/do ... r_test.zip
Attachments
screen001.jpg
screen001.jpg (12.36 KiB) Viewed 1577 times
Last edited by federico on Sat Oct 15, 2005 10:27 am, edited 1 time in total.
hike1
RF FAQ-Keeper
Posts: 607
Joined: Tue Jul 05, 2005 4:19 am
Contact:

Post by hike1 »

That's great, but I'd like to drive a car up and down hills, not
watch one.
User avatar
jonas
Posts: 779
Joined: Tue Jul 05, 2005 5:43 pm
Location: Texas, USA
Contact:

Post by jonas »

I can barely tell what that is! :(
Jonas

Focused, hard work is the real key to success. Keep your eyes on the goal, and just keep taking the next step towards completing it. If you aren't sure which way to do something, do it both ways and see which works better. - John Carmack
User avatar
AndyCR
Posts: 1449
Joined: Wed Jul 06, 2005 5:08 pm
Location: Colorado, USA
Contact:

Post by AndyCR »

this is great! is there a way to make the front wheels turn in synch with each other, and the vehicle actually react to that? for instance, take a real front-wheel-drive car, and turn the steering wheel hard to the right, then hit the gas. is there a way to do something similar with the current state of the physics?

the more i see of this, the more impressed i am... you are a master... :D
User avatar
federico
RF Dev Team
Posts: 443
Joined: Tue Jul 05, 2005 3:14 pm
Contact:

Post by federico »

I hope you are talking about Nout not about me: He is he only Physics Master. :wink:

This is only a modification I made to see how effectively the CreateHinge parameters work. After all, if we have to work hardly on that, it is better to have a nice-looking car instead of a "box car". Said that, the script is the same except: the bounding box of the wheels is a sphere and not a box. the motor is disabled, the wheels/joints position fits the car geometry, there is a Start Order with the motor command.
The real work here, was made by Nout. I hope that he enjoys my try to beautify his work and he tries to figure out how to turn that wheels...
User avatar
federico
RF Dev Team
Posts: 443
Joined: Tue Jul 05, 2005 3:14 pm
Contact:

Post by federico »

From the tokamak sample 8 of a car:
This sample demonstrate the simple implementation of a car.
The wheels are modellded as a ray-cast sensors with controller callback.
can you help us to figure out how to make somethinhg similar? Is it possible to make something similar to "sample 8" with the PhysicsScript? I think yes cause sensors are functional...or am I wrong?
I have to admit that I have understood sensors only in a theorical way but in practice I haven't understood nothing at all. What method have chose to implement the Physic vehicle? The same of sample 8?
User avatar
AndyCR
Posts: 1449
Joined: Wed Jul 06, 2005 5:08 pm
Location: Colorado, USA
Contact:

Post by AndyCR »

i meant Nout, i thought he was the one who made the car demo (i get you two mixed up alot, sorry), but you're an absolute genius too... especially with scripting.!

</sorryofftopic>
Nout
Posts: 136
Joined: Tue Jul 05, 2005 5:14 pm

Post by Nout »

federico, first of all, great job done with the scripting and the demo! It's fantastic help and brings good inspiration. Nice to see how you can use the commands and realiwe good results. Also for me, this is very encouraging!

Now back to some of your questions
2) Car_Test. "LeftClick" to apply a torque on the front wheels. Any idea on how to turn the wheels in the examples, Nout, and make it work like a real car? This is the main question of my previous posts.
I've extended the vehicle entity and it is now able to:
a) let the wheels rotate forward or backward when you are driving (rotation speed is depending on the real driving speed)
b) rotate the wheels left an right while stearing
The car chassis has a buggy rotation problems. Are these the Y-Axis rotation problems that you solved in the next release?
Yes, and the y-rotation bug is solved (it was a genesis issue). All rotations fully work correctly now and look a lot better ;-) ).
Does the physic development proceed in the desired way? Are you plannig an upgrade (exe + headers)?
It progresses slower then I'd like it have it moving. I'm bussy with several extensions, not only physics. In the new code, still a few items are still buggy which I try to closed before releasing, eg the collision table and collision handler.

Anyway, I've decided to release what I have latest by end next week (24 Oct) It will be a second alpha release (including exe, headers, genesis updates, source code, documentation and a few examples)
Most important new things added is a scriptable light and spotlight. It allows you for example to make lights that softly turn on when the skydome starts showing the moon, change the color of lights depending on attributes etc...
From the tokamak sample 8 of a car:
This sample demonstrate the simple implementation of a car.
The wheels are modellded as a ray-cast sensors with controller callback.
Can you help us to figure out how to make somethinhg similar? Is it possible to make something similar to "sample 8" with the PhysicsScript? I think yes cause sensors are functional...or am I wrong?
Sample 8 was my starting point for writing the code for the vehicle entity. It uses the same concepts, eg raycasting, and is fully embedded in the entity to make your life easy. The callback feature is a must for correct vehicle control, but it would be way too slow to put that in scripting.

Another new thing added: A scriptable Genesis-RayCollision command. I'm using it to detect that a physics scripted UFO is 100 pixels above the floor and needs to start breaking (Apply upwards force) + to activate a flame entity (simulating the breaking engine)
User avatar
federico
RF Dev Team
Posts: 443
Joined: Tue Jul 05, 2005 3:14 pm
Contact:

Post by federico »

24 october! I can't wait! :wink:

1)I'm really curious about the new physicsvehicle modifications. Anyway, could you explain how to obtain the vehicle steering result using the script or commenting the physicsvehicle entity code in the source? It could be a useful case study for understand sensor and callback. I'd like to create a bycicle.

2) Some another quick question about RigidBody:

Body[0] = CreateRigidBody("Body0", "box_centered.act",4,0.5,1, 255, PosX, PosY, PosZ, 0,0,0, 0,0,0 , false, ALPHA, "Box 0", 1, 0,0,0,0, Mass);

Body[0] = CreateRigidBody(BodyName, ActorFile, ScaleX, ScaleY, ScaleZ, Alpha, PosX, PosY, PosZ, ?,?,?, ?,?,? , Shadow, Alpha?, GeometryType, ?, ?,?,?,?, Mass);

blue or orange highlight are rotation I didn't understand well. Red highlight is the width height depth of the bounding box?
it works, though....

Instead in one of your script you used:
Body[0] = CreateRigidBody("Ball0", Actor,1,1,1, PosX, PosY, PosZ, 0,0,0,Mass, true, ALPHA, "Box", 0, 0, 0, 1, 1,0,0,0);
but in the previous example:
Body[0] = CreateRigidBody("B0", "box_centered.act",1,0.3,1, 255, PosX, PosY, PosZ, 0,0,0, 0,0,0, true, ALPHA, "Box 0", 1, 0,0,0,0, Mass);
and in the documentation:
BodyId = CreateRigidBody(ActorName, ActorFile, ActorScaleX, ActorScaleY, ActorScaleZ, PosX, PosY, PosZ, RotX, RotY, RotZ, ShowShadow, ShadowAlpha, GeometryType, MaterialId, Mass);
I got confused...

3) I've quite understand hingejoint but I don't kown how I can create a joint that enable rotation on the Y axis. I mean that now theese examples show rotation on X axis like a wheel of a car. Is there a way to specify that the hinge should work on Y axis like the top rotor of an helicopter or the hinge of a door or the arm of the steer (I also want to try to create a steer in this way). In ths way, applying a Y rotation force (torque or twist) on the Y axis, the joint should allow rotation of the bodies accordingly with the MinLimit MaxLimit of the hinge.
User avatar
jonas
Posts: 779
Joined: Tue Jul 05, 2005 5:43 pm
Location: Texas, USA
Contact:

Post by jonas »

Wow! I've been around Rf for about I year and I've watched as it has come from 068 which was ok to now :P Physics and moving lights, I think I might delay making my game a little longer till your demo is out with the physics and the car capabilities. I'm glad your working on rf now after gekido and the original rf team started working on beyond virtual and got busy. I'm not saying no one else is but you know what I mean. :oops:
Jonas

Focused, hard work is the real key to success. Keep your eyes on the goal, and just keep taking the next step towards completing it. If you aren't sure which way to do something, do it both ways and see which works better. - John Carmack
User avatar
federico
RF Dev Team
Posts: 443
Joined: Tue Jul 05, 2005 3:14 pm
Contact:

Post by federico »

Hinge Demo 1

Code: Select all

{

PosX [0]
PosY [0]
PosZ [0]
Dx [0]
Dy [0]
Dz [0]

Dx_tyre1 [0]
Dy_tyre1 [0]
Dz_tyre1 [0]
Dx_tyre2 [0]
Dy_tyre2 [0]
Dz_tyre2 [0]
Man_Y [0]

Mass [1]
Scale [1]
ALPHA [255]
MyBodyId [-1]
SenId1 [-1]
RocketId [-1]
KeyReleased [true]
Depth [0.0]
TORQUE_REAR [0]
TORQUE_FRONT [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 = -450;
PosZ = 0;
DefineMaterial(1, 10, 0.5);

Body[0] = CreateRigidBody("Body0", "hinge1.act",8,8,8, 255, PosX, PosY, PosZ, 0,0,0, 0,0,0 , true, ALPHA, "Box 0", 1, 0,0,0,0, 0.1 );
CreateHingeJoint(Body[0], -1, PosX, PosY+Dy, PosZ, 0, 0, 0, 0, 0, -1, 0, 0); 
CreateHingeJoint(Body[0], -1, PosX, PosY, PosZ, 0, 0, 0, 0, 0, -1, 0, 0); 

Dx = GetBodyBBox(Body[0], 0);
Dy = GetBodyBBox(Body[0], 1);
Dz = GetBodyBBox(Body[0], 2);

Body[1] = CreateRigidBody("Body1", "hinge2.act", 8,8,8, 255, PosX, PosY, PosZ,0,0,0, 0,0,0, true, ALPHA, "Box 0", 0, 0,0,0,0, 0.1);
CreateHingeJoint(Body[0], Body[1], PosX, PosY+Dy, PosZ, -180, 180, -180, 180, 0, -1, 0, 0);
CreateHingeJoint(Body[0], Body[1], PosX, PosY, PosZ, -180, 180, -180, 180, 0, -1, 0, 0);

} ] 


Start[ () 
{
Console(true);
ShowPhysicsBBox(false);

if(self.leftmousekey_pressed) 
{
SetTorque(Body[1], 0, 100, 0, true); 
}
if(self.rightmousekey_pressed) 
{
SetTorque(Body[1],0, -100, 0, true); 
}
} ]

}
Now I know how to create a vertical joint on the Y axis. I use joints with the jointlenght parameter set to zero, so they can freely move in any direction, but I use 2 joints. One up and One down the body, like a door with 2 hinge (one up and one down).

Ao---------\
..|............|
..|............|
..|............|
Bo---------/

A is the up joint and B is the down one.

in this demo the first body is connected to 2 points declared in world coordinates. This is possible using the -1 parameters instead of the second Body. Limits are set to 0 so no movements are allowed for this body.
The second body is connected with the first using 0 jointlenght and 180° of limits.

In the Start order I put some command (SetTorque) to apply rotation to the body. The 2 model are build in milkshape with the edge on the origin so the rotation isnt applied on the centre of the body. MIxing the 2 constrains the only movement allowed is on the Y axis.
USE RIGHT MOUSE BUTTON TO ROTATE THE GREEN BLOCK CLOCKWISE
USE LEFT MOUSE BUTTON TO ROTATE THE GREEN BLOCK COUNTERCLOCKWISE


Download:
http://realityfactory.altervista.org/do ... _demo1.zip
Attachments
screen000.jpg
screen000.jpg (10.36 KiB) Viewed 1501 times
User avatar
federico
RF Dev Team
Posts: 443
Joined: Tue Jul 05, 2005 3:14 pm
Contact:

Post by federico »

Hinge Demo 2

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 :D
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 Hinge Car. 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...). It would be more simple if the joint could be viewed like a scriptpath to see their exactly position in the world.

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.

Commands:
Left Mouse Button = accelerate
Right Mouse Button = decelerate / retro
Keyboard Arrows = Left/Right

8 = Change Camera
SPACE = Apply an Upward Impulse


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.

Three levels:
a) Hinge Car: a car in a box...
b) Down the Hill 2 : steer down the hill!
c) Up The Hill: Climb the Hill!!! (Go Hike! Go!)
Download:
http://realityfactory.altervista.org/do ... ge_car.zip
Attachments
screen000.jpg
screen000.jpg (22.02 KiB) Viewed 1493 times
screen001.jpg
screen001.jpg (12.76 KiB) Viewed 1493 times
Nout
Posts: 136
Joined: Tue Jul 05, 2005 5:14 pm

Post by Nout »

Fredrico,

I'm very happy you like the scriptable MECANO for physics! I've spend quite some time to make it and enjoy seing who fast you learned to play with it. This is excellent news for me!

And plese stay spamming this forum with our eamples. It's very usefull for new comers in physics. So keep the exploration going and keep posting your nice examples
Nout
Posts: 136
Joined: Tue Jul 05, 2005 5:14 pm

Post by Nout »

2) Some another quick question about RigidBody:

Body[0] = CreateRigidBody(BodyName, ActorFile, ScaleX, ScaleY, ScaleZ, Alpha, PosX, PosY, PosZ, ?,?,?, ?,?,? , Shadow, Alpha?, GeometryType, ?, ?,?,?,?, Mass);
This command was updated relative to the last alpha version of September. Here the new syntax

BodyId = CreateRigidBody(ActorName, ActorFile, ActorScaleXYZ, ActorAlpha, PosXYZ, OffsetXYZ, RotXYZ, ShowShadow, ShadowAlpha, GeometryType, MaterialId, BreakageType, BreakageMass, BreakageMagnitude, BreakageAbsorption, Mass);
OffsetX,Y,Z: The offset applied between the physics bounding box and the actor.
RotX, RotY, RotZ: Initial rotation of the actor in X, Y and Z, defined in degrees
MaterialId: For each body you can assign a material by defining its material_Id. A material specifies the bouncing and friction properties of this material. See the DefineMaterial command.

ExtendRigidBody(BodyId, ActorName, ActorFile, ActorScaleXYZ, ActorAlpha, PosYXZ, Offset, RotXYZ, ShowShadow, ShadowAlpha, GeometryType, MaterialId, BreakageType, BreakageMass, BreakageMagnitude, BreakageAbsorption, Mass);

BodyId = CreateStaticBody(ActorName, ActorFile, ActorScaleXYZ, ActorAlpha, PosYXZ, OffsetXYZ, RotXYZ, ShowShadow, ShadowAlpha, GeometryType, MaterialId, BreakageType, BreakageMass, BreakageMagnitude, BreakageAbsorption);

ExtendStaticBody(BodyId, ActorName, ActorFile, ActorScaleXYZ, ActorAlpha, PosYXZ, Offset, RotXYZ, ShowShadow, ShadowAlpha, GeometryType, MaterialId, BreakageType, BreakageMass, BreakageMagnitude, BreakageAbsorption);

CreateHingeJoint(BodyId1, BodyId2, PosXYZ, RotXYZ, MinAngle, MaxAngle, MinTwist, MaxTwist, JointLength, MotorType, DesiredValue, MaxForce)
Please note that by default a hinge rotates around the Y-axis. You can change this axis, by applying a rotation on the hinge, which is relative to this default axis. To make a hinge rotating around the X-axis, apply rotation (90, 0, 0). To make a hinge rotating around the Z-axis, apply rotation (0, 0, 90).
MotorType: An integer that defines the motor type. if 0, a velocity motor is assigned. If 1, a TBD motor is assigned. Any other value disables the motor.
DesiredValue: The wanted speed of the motor
MaxForce: The maximum force applied to reach the desired value

More commands + text will be in the docs coming in a few days

new physicsvehicle modifications
They are a bit on the background right now. The scripts you are making, I relatively fast can port something similar into the PhysicsVehicle entity by code, and it will have suspension aswell (this part of code is already in) :P
3) I've quite understand hingejoint but I don't kown how I can create a joint that enable rotation on the Y axis.
The explination of the new hinge command above answers this
I've created a bike, if anyone is interested...
Yes, I'm sure interestested. aarnout@gmail.com, all is welcome there
It would be more simple if the joint could be viewed like a scriptpath to see their exactly position in the world.
What is a scriptpath?
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.
You can speed up the physics by:
a) using smaller geometry (RF uses very large sizes, relative to the units used in the physics system, which I can not change (it's frozen inside Tokamak)). This is the best solution, as it is not changing frame rates
b) You can decrease the value for IterationTime in the PhysicsSytem entity. This will increse the number of physic simulations made within 1 RF frame. The smaller the number, the more physic iterations, which will slow down the frame rate, but speed up the physics.
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.
Did you assign friction to both, the floor and the body making friction with the floor?

Keep up the good work!
hike1
RF FAQ-Keeper
Posts: 607
Joined: Tue Jul 05, 2005 4:19 am
Contact:

Post by hike1 »

Federico, I tried out your car driving, pretty good, can you
do this in 1st person?

I assume you've tried the ogre car physics demo? http://www.walaber.com It's fun for about 5 minutes, then I go, 'what now?'

I'm not that interested in physics beyond driveable vehicles like in battlefield 42, right now
Nout's .exe has 2 show stopper bugs, the encrypting doesn't
work and the projectiles are hosed.


K, I tried it out in my main 1 GB development directory,
The two large levels loaded, inventory was there, but the
player's projectiles would only fire to the west or east. The
baddies' projectiles fired at the player, but they were all wide left by about 5 feet.

Then I put it in my Demo directory, the one with the encrypted .vfs- it complained about 'treepalm.act' I put it outside the VFS,
same with minegrav.act, outside VFS. Then I got this-



Loaded media\actors\treepalm.act
Loaded media\actors\minegrav.act
Initializing Static Mesh Subsystem...
OpenRFFile: File open attempt in DOS-mode failed, try now in VFS, file 'media\actors\smoothne.act'
Loaded media\actors\smoothne.act
CStaticMesh: can't create def from file 'smoothne.act'
CStaticMesh: can't create VertMatList from file 'smoothne.act'
Shutting Down AVIFile Video Subsystem...
Post Reply