Simple Car Demo!

Topics regarding Scripting with Reality Factory
User avatar
federico
RF Dev Team
Posts: 443
Joined: Tue Jul 05, 2005 3:14 pm
Contact:

Simple Car Demo!

Post by federico »

Ok, Let's start again from the beginning.

Simple Car Demo 1.
This is a simple car with six hinges (4 for the wheels,2 for the steer). No suspension. The model is the half-life 2 buggy (it seems quite 'rigid', like this car is). The archive includes two map: 1) a flat box with a ramp and some crates. 2) a bsp terrain. Note that I haven't optimized anything. Consider also that this a starting point to modify the source and avoid all the calls out the physics script. now there are 3 useless pawns required to track the wheels rotation. In the terrain level you will see the "fall through the floor bug". It's an annoying bug caused by the slowness of genesis that causes a missing collision for tokamak. Probably when all the issues about extra pawns are fixed this doesn't happen anymore. Use 'J' to make car fly over the bad collision zone.
For the dust effect I used the standard RF smoke, but it has to be optimized (when the car flies, it hasn't to do any smoke naturally) but i don't know how to tell to the script that the car is flying. Maybe a sensor but I don't know how to make it work yet. Also here there are external script calls for a SetEventState to activate the spout trigger, that has to be eliminated. In my old Realityracer I used another trick, attaching a weapon that leaves a skidding decal on the ground. I think that can be made also for this car (implementing the appropriate firing script command). There are some bug in this rf release so please exit and start again the app if you want to reset the scene. If you go in the option / video menu you can enable stencil shadows for the car chassis (slowing down together...). You can break the wheels joints using '6' and re-glue them using '7' (thanks to the Nout special effects!) probably in the future will be implemented the SetBreakCriteria command (read the Nout's docs).

Installation
Simply download RF073withPhysics7Jan2006.zip from http://realityfactory.altervista.org/download/ then patch the workfolder with the simple_car1.zip archive that you found here: http://realitychess.altervista.org/physics/

Controls
Left / Right Mouse Buttons: Accelerate / Decelerate
Left / Right arrow keys : turn left - right
J : Jump
SPACE : handbrake (buggy)
'8': change camera (follow / backward / lateral)
'6-7': break - glue wheel joints

Quick Hack Tutorial
In the Init order (executed once) of the scripts/car/rigid_car1.p script you will find the car creation commands. Body[0] is the chassis. it calls for an existing pawn ('CHASSIS'). you can modify the mass of the car (Mass parameter). Modify also the mass of ExtendRigidBody object that you find under Body[0]. These are the extended geometries of the car chassis.
The wheels are Body[1] / Body[2] (rear wheels) and Body[5] / Body[6] (front wheels). You can change the mass as above and the dimension of the wheel. The first triplet after the .act extension filename is the XYZ scale of the actor.
Body[3] and Body[4] are invisible geometries that are the fulcrum of the steer. you can affect the car steer changing the variable declaration MAX_STEAR_ANGLE [33] (in degrees).
You can change the friction of the wheels changing the 2nd parameter in the DefineMaterial(1, 6, 0.5); command. Now is 6, a high value, but remember that the wheel bounding geometry is a sphere. The third parameter is the Restitution. You can also change the world friction and restitution in the PhysicsSystem entity in the level using the world editor (3dt included).
In the Start order (executed every frame) you can uncomment
//SetTorque(Body[1], X_FINAL_TORQUE, 0, Z_FINAL_TORQUE, true); //uncomment for 4wd
//SetTorque(Body[2], X_FINAL_TORQUE, 0, Z_FINAL_TORQUE, true);
to have a 4wd car, and after, eventually, comment the above two lines to have a rear-driven car.
Changing the TORQUE_REAR value in this if/else block, you will change the engine force:
if(((self.leftmousekey_pressed=true)and((self.key_pressed=46)=false)and((self.key_pressed=33)=false))and(((self.key_pressed=58)=true)or((self.key_pressed=58)=false))and(((self.key_pressed=57)=true)or((self.key_pressed=57)=false)))
{
TORQUE_REAR=260;
X_FINAL_TORQUE = TORQUE_REAR*(B_PERC/100);
Z_FINAL_TORQUE = TORQUE_REAR*(A_PERC/100);
}
else
{
X_FINAL_TORQUE = -TORQUE_REAR*(B_PERC/100);
Z_FINAL_TORQUE = -TORQUE_REAR*(A_PERC/100);
if(((self.rightmousekey_pressed)and((self.key_pressed=46)=false)and((self.key_pressed=33)=false))and(((self.key_pressed=58)=true)or((self.key_pressed=58)=false))and(((self.key_pressed=57)=true)or((self.key_pressed=57)=false)))
{
TORQUE_REAR=260;
}
else
{
TORQUE_REAR=TORQUE_REAR*0.4;
if(TORQUE_REAR<2)
{
TORQUE_REAR=1;
}
}
}
I hope that this can help you. And I hope that we can finally have a stable RF with physics in the near future thanks to a new Tokamak release. Please give an enormous credit to Nout for the Physics Development. It has really changed the RF face! Many thanks, master. :wink:

Screens.
ImageImage
ImageImage
ImageImage
User avatar
federico
RF Dev Team
Posts: 443
Joined: Tue Jul 05, 2005 3:14 pm
Contact:

Post by federico »

A note for Nout:

This is the script piece to detect the wheel skidding:
//track motor speed
MY_SPEED_X = AbsFloat( GetVelocity(Body[0], 0) );
MY_SPEED_Y = AbsFloat( GetVelocity(Body[0], 1) );
MY_SPEED_Z = AbsFloat( GetVelocity(Body[0], 2) );
MY_SPEED = Integer(MY_SPEED_X + MY_SPEED_Y + MY_SPEED_Z) ;

//track wheel speed
WHEEL_SPEED = (Integer(AbsFloat(GetAngularMomentum(Body[3], 0)) + AbsFloat(GetAngularMomentum(Body[3], 2)))/1000) * 3; // this tracks the left wheel speed

// check for wheel skidding
if(((MY_SPEED > (WHEEL_SPEED + (MY_SPEED * 0.2))) or (MY_SPEED < (WHEEL_SPEED - (MY_SPEED * 0.2)))) and (WHEEL_SPEED > 20))// the engine speed is consistently slower or faster than the wheels
{
//debug("I_m skidding!!!"); // do the skid stuff - smoke, decal
SetGlobal( 1, "Int", 1);
}
else
{
SetGlobal( 1, "Int", 0);
}
I used your new command GetAngularMomentum so i thought that you were happy to know.
This is an approximation but it works quite good. The script can be extended to track every wheel to have differentiate dust effect.
WHEEL_SPEED + (MY_SPEED * 0.2) I use 0.2 as threshold for the skidding. I need to found a way to make spout the dust only when the wheel is in contact with the ground. The SetGlobal command has to be replace by an implementation of SetEventState. 8)
User avatar
AndyCR
Posts: 1449
Joined: Wed Jul 06, 2005 5:08 pm
Location: Colorado, USA
Contact:

Post by AndyCR »

WOW!!! thats AWESOME! :o

its realistic! i flipped my car on its side and rammed through boxes quite happily, lol. nearly flipped.
User avatar
animatrix
Posts: 134
Joined: Thu Jul 07, 2005 10:51 pm

Post by animatrix »

Holy Crap!!!!! thats awsome...... :D
hike1
RF FAQ-Keeper
Posts: 607
Joined: Tue Jul 05, 2005 4:19 am
Contact:

Post by hike1 »

I didn't get that demo, I got one with other robot cars and a city, it was fun, where's the link to the boxes car demo?
User avatar
federico
RF Dev Team
Posts: 443
Joined: Tue Jul 05, 2005 3:14 pm
Contact:

Post by federico »

Installation
Simply download RF073withPhysics7Jan2006.zip from http://realityfactory.altervista.org/download/ then patch the workfolder with the simple_car1.zip archive that you found here: http://realitychess.altervista.org/physics/
User avatar
federico
RF Dev Team
Posts: 443
Joined: Tue Jul 05, 2005 3:14 pm
Contact:

Post by federico »

Some new screen about a community project. I can't tell you more before we are very close to some result. but wht do not show some dev screen, without shadows, with scriptpath showing, in an horrible test level? :D

the yellow car is the player car, the red car is an AI that follows the path reading the scriptpoint capital to learn how to drive. for example A1->B2->A3->C4 etc... Where A= 70 kmH, B = 50, C = 30 etc... the car detect the difference between his speed and ideal speed and accelerates or brakes. I have to implement new intelligent AI functions such as obstacle avoidance and advanced pathfinding.
Attachments
What a jump!
What a jump!
screen006.jpg (22.82 KiB) Viewed 2316 times
...ehm...
...ehm...
screen007.jpg (11.45 KiB) Viewed 2316 times
overtaking...before
overtaking...before
screen000.jpg (24.56 KiB) Viewed 2317 times
User avatar
federico
RF Dev Team
Posts: 443
Joined: Tue Jul 05, 2005 3:14 pm
Contact:

Post by federico »

continuing the screens...
Attachments
screen005.jpg
Ehi! he touch me!
(37.01 KiB) Downloaded 102 times
overtaking...after
overtaking...after
screen001.jpg (14.84 KiB) Viewed 2314 times
hike1
RF FAQ-Keeper
Posts: 607
Joined: Tue Jul 05, 2005 4:19 am
Contact:

Post by hike1 »

The car demo is very fun. You might want to get rid of the dark
areas in the corners, as I can't see where to turn in them. Also
an idle, accelerate, run, decelerate noise would be good.

Is there a way to just have the player actor move like the car
without the car showing? I'm only doing 1st person.

Then we could paste 'in the driver's seat' HUD bitmaps on the
screen, then we'd have Tribes 2, Battlezone 2 type hover vehicles.
User avatar
federico
RF Dev Team
Posts: 443
Joined: Tue Jul 05, 2005 3:14 pm
Contact:

Post by federico »

@ hike
yes, I'm trying to implement sounds but there is something more to be done with the physics implementation to have the correct response of the collision table to play the proper collision sound. So I'm waiting thinking about a solution (naturally Nout can have a manna-from-heaven for this... :lol: ).
To create an hover, watch to my marble madness prototype in the physics depot: http://realitychess.altervista.org/physics/. if you press F1 you will have the 1rst person view of the ball, somenthing similar to hover you talk about.
___

I'm working hard on the car opponent Ai and I have to show you my result. Much more has to be done to avoid conflicting commands but I'm quite surprised by the quickness of the results. I used the genesis RayCollisioncommand to read the depth of three rays: 1) in front 2) 45° left 3) 45° right. Reading this results i can arrainge the Ai in a way to think what the better way to avoid an obstacle. At this stage the opponent race in the thrack and can avoid obstacles leaving the path and then returning back. if the opponent is stopped by an obsacle can use the backward gear and detect if if has the space to return to the path.
i set up a page with those videos. Check them at: http://realitychess.altervista.org/video

there is also the buggy car in the VET format to test this great technology. But you need the Viewpoint Media Player plugin.
I hope you like it! :wink:
hike1
RF FAQ-Keeper
Posts: 607
Joined: Tue Jul 05, 2005 4:19 am
Contact:

Post by hike1 »

if you press F1 you will have the 1rst person view of the ball, somenthing similar to hover you talk about.

I also get this in your car demos by pressing F1, only there's
a car in the view and your player's hands.
User avatar
federico
RF Dev Team
Posts: 443
Joined: Tue Jul 05, 2005 3:14 pm
Contact:

Post by federico »

@hike
open the .p scripts in the scripts/car folder you will see theese kind of declaration in the init order (here the script defines the creation of the physics bodies):

Body[0] = CreateRigidBody("Body0", "CHASSIS",3,3,3, 255, PosX, PosY, PosZ, 0,0,0, 0,0,0 , false, 100, "Box 30 2 14", 0, 0,0,0,0, Mass);

the red parameter is the alpha of the body. change it to 0 and the body becomes invisible.

@all
For the ones who haven't noticed yet:
http://realitychess.altervista.org/video/

What do you think? :wink:
User avatar
Spyrewolf
Posts: 450
Joined: Tue Jul 05, 2005 4:53 am
Location: Wellington::New Zealand

Post by Spyrewolf »

WOW great Demo's Federico!!!!

those physics demos are nothing but spectacular!!!

you really have created something very speacial here
i had heaps of fun driving around the map this was soo Cool!!

my only wish is this would be incorporated ito the main release
User avatar
federico
RF Dev Team
Posts: 443
Joined: Tue Jul 05, 2005 3:14 pm
Contact:

Post by federico »

thank Spyrewolf!
but always remember that the only one, great, marvellous Physics Master is Nout! :lol:
We have a silent agree. I create the demos and test the dev so he can approach completely the programming side. This is why we are going so fast. Now we are working to put all the things togheter, and we are planning a great demo, using some community brains! This cooperation between us is the mark of this fast growth. All the lacking fetures had to be approached in this way! We are close, really close. Remember that the last RFwithPhysics, that you can find here http://realityfactory.altervista.org/download/ is quite similar to RF075, because the most part the new script commands are Nout's implementation and it onlylacks only the stability that QoD can provide. :wink:
User avatar
fps
Posts: 504
Joined: Mon Sep 26, 2005 9:54 pm
Location: in a magical land devoid of hope, happiness, and sanity.

Post by fps »

Are you going to put these awsome physics into the next release of RF???
I hope so because they are awsome!!!
All i think it needs is the ability to define several impact sounds for when the boxes hit the ground and land in warer and stuff, that would rock!

1 question though, can the physics of the boxes being hit with the car work with the regular player charector and other pawns instead of the HL buggy?

Thanks,
Post Reply