Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (AndrewAMD, 7th_zorro, dr_panther), 1,297 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
simple car physics #255294
03/09/09 12:07
03/09/09 12:07
Joined: Jan 2009
Posts: 11
KuRdisTaN - IraQ
dlOvanO Offline OP
Newbie
dlOvanO  Offline OP
Newbie

Joined: Jan 2009
Posts: 11
KuRdisTaN - IraQ
//hello evrybody....
//i have some of script of physics for wheels(car) it is from
//project cat level
//it is work well

//contents:
//1- 3 wheels on for rotating car and 2 for pushing car ;
//2-chassis of car
//actions :
//FLInit() for steering wheel
//RRInit() for 2 whees pushing car

//this is all script:



#include <acknex.h>
#include <default.c>
var temp[3];
var temp2[3];
ENTITY* pFocus;
//Car constants
var maxTorque= 1000; //1200 // maximum torque applied to rear wheels
var maxTorqueBrake=2000; // this will be applied to rear wheels when hitting brakes or handbrake
var maxAngSpeed= 120; // max. angular speed of wheels; max linear speed depends on wheel radius
var massWheel= 30; // mass per wheel
var massChassis= 10; // mass for chassis lighter than wheels so it doesn't tilt
var fricWheel= 100; //100 // friction of wheels -god for "in the water"
var fricChassis= 20; //20 // friction of chassis (low to avoid getting stuck on ramps
var dampChassis= 5; // damping lin/ang for chassis
var dampWheel= 15; //15 // damping ang for wheels
var suspensionERP= 95000; //90000; // how quickly shocks are reduced to correct position (100,000 max, 0: never)
var suspensionCFM= 250; //500 // how far shocks can overshoot (0: never, 100,000 max)
var jumpRechargeDelay=1.5; //1.5 // time before user is allowed to jump again in secs
var jumpForce= 3000; //3000; // force multiplier for jumps
var gravity=1800; //2000; // gravity along -Z axis
// Steering constants
var accelKeyboard=2; // acceleration multiplier for key control
var accelSteering=3; // acceleration multiplier for steering key control
// these values depend on MDL and WMP where car is located
var vecUp[3] ={0,0,1}; // up axis, usually +Z
var vecRight[3] ={0,-1,0}; // chassis right axis
var vecHookOffset[3] ={0,-15,40}; // this is offset from chassis center where lifter hook will be installed
var vecDriverOffset[3]={-35,10,34}; // where camera will be located relative to chassis center (cockpit)
var vecChaseOffset[3] ={-150,0,60}; // where camera will be located relative to chassis center (chase)
// Controller setup
#define KEY_FWD key_w
#define KEY_BWD key_s
#define KEY_LEFT key_a
#define KEY_RIGHT key_d
#define KEY_BRAKE key_space
// physics global vars
var DoShutdown=0; // set to 1 and wait a while before reloading level
var DoSteering=1; // set to 1 to enable all controls 0 for pause
var linSpeed; // car speed in XY
var downSpeed; // car speed in Z direction
var angSpeed; // current wheel angular speed along y axis of wheel
var targetSpeed=0; // desired angular speed (if torque permits)
var targetSteer=0; // desired steering angle
ENTITY* pChassis; //our car objects
ENTITY* pFL;
ENTITY* pRR;
var wheelFL;
var wheelRR;
var commonWheelHeight=-100000;
// setup all 4 wheels
function InitWheel()
{
set(my,SHADOW);
if (commonWheelHeight<=-100000) {
commonWheelHeight=my.z; // store z for other wheels to come
} else {
my.z=commonWheelHeight; // Set all wheels to same height
}
vec_set(my.skill1, my.x); // store pos/orientation for reset
vec_set(my.skill4, my.pan);
phent_settype(my, PH_RIGID, PH_SPHERE);
phent_setmass(my, massWheel, PH_SPHERE);
phent_setgroup(my, 2);
phent_setfriction(my, fricWheel);
phent_setdamping(my, 15,dampWheel);
phent_setelasticity(my, 0, 100); // bounciness
}
action FLInit()
{
set(my,PASSABLE);
while(!pChassis) { wait(1);}
pFL=my;
InitWheel();
// make wheel constraint pointing up and towards center
wheelFL= phcon_add(PH_WHEEL, pChassis, my);
phcon_setparams1(wheelFL, my.x, vecUp, vecRight);
phcon_setparams2(wheelFL, vector(0,0,0), nullvector, vector(suspensionERP, suspensionCFM,0));
reset(my,PASSABLE);
}
action RRInit()
{
set(my,PASSABLE);
while (!pChassis) { wait(1);}
pRR=my;
InitWheel();
// make wheel constraint pointing up
wheelRR= phcon_add(PH_WHEEL, pChassis, my);
phcon_setparams1(wheelRR, my.x, vecUp, vecRight);
phcon_setparams2(wheelRR, vector(0,0,0), nullvector, vector(suspensionERP, suspensionCFM,0));
reset(my,PASSABLE);
}

function SpeedControl()
{
var dir;
while (1)
{
dir = (KEY_BWD - KEY_FWD);
//speed up over time for keyboard (relative acceleration)
targetSpeed += dir*accelKeyboard* time_step;
var torque;
torque=maxTorque;
// damp down speed over time if no key pressed
if (dir==0)
{
targetSpeed *=1-(time_step*0.02); torque=maxTorque/2;
if (abs(linSpeed)<20) // switch off opposing torque so we can roll down hills
{ torque=0; targetSpeed *=0.5;}
}
//targetSpeed= clamp(targetSpeed,-maxAngSpeed*0.25, maxAngSpeed);
phcon_setmotor(wheelRR, nullvector, vector(targetSpeed, torque,0), nullvector);

if (KEY_BRAKE) // stoping
{
phcon_setmotor(wheelRR, nullvector, vector(0, maxTorqueBrake,0), nullvector);
}
wait(1);
}
}


function CalcSteeringScale()
{
return (1-(abs(angSpeed)/(maxAngSpeed+60)));
}


action CarInit()
{
//ChassisInit();
vec_set(my.skill1, my.x); // store pos/orientation for reset
vec_set(my.skill4, my.pan);
pFocus=my;
set(my,SHADOW|PASSABLE);
vec_set(vecRight,vector(0,-1,0)); // reset right vector (in case of level restart)
vec_rotate(vecRight,my.pan); // rotate right vector to correspond to car orientation
phent_settype(my, PH_RIGID, PH_BOX);
phent_setmass(my, massChassis, PH_BOX);
phent_setgroup(my, 2); // all car parts in group2 ->no Collisions
phent_setfriction(my, fricChassis);
phent_setdamping(my, dampChassis,dampChassis);
phent_setelasticity(my, 10, 100); // little bouncing
pChassis=my;
pChassis.emask = ENABLE_FRICTION;
vec_set(temp, my.x);
vec_add(temp, vecHookOffset);
reset(my,PASSABLE);
ph_setgravity(vector(0,0,-gravity));

my.material = mat_metal;
SpeedControl();
//SteerControl();/////////////////////////////
var direction; //delta change
while (1)
{
direction= (KEY_RIGHT-KEY_LEFT);
direction*= CalcSteeringScale();
targetSteer+= direction*accelSteering* time_step;
targetSteer=clamp(targetSteer,-30,30);
if (direction!=0)
{
phcon_setparams2(wheelFL, vector(targetSteer,targetSteer,0), nullvector, vector(suspensionERP, suspensionCFM,0));
} else {
targetSteer*=1-(time_step*0.25);
if (abs(targetSteer)<1) { targetSteer=0; } // force to 0
phcon_setparams2(wheelFL, vector(targetSteer,targetSteer,0), nullvector, vector(suspensionERP, suspensionCFM,0));
}
wait(1);
}
}



STRING* levelname = "example.wmb";
function main()
{
video_mode=7; //800x600
shadow_stencil= ON;
d3d_autotransparency = ON;
wait(1);
level_load(levelname);

wait(1);
}



I hope you it usefull for you grin

dlovanooo@ymail.com



Last edited by dlOvanO; 03/09/09 12:46.

....Never Say I don't Say I'll try....
Re: simple car physics [Re: dlOvanO] #255947
03/13/09 19:22
03/13/09 19:22
Joined: Nov 2006
Posts: 19
Bursa, TR
deathknt Offline
Newbie
deathknt  Offline
Newbie

Joined: Nov 2006
Posts: 19
Bursa, TR
thank you very much


One ring to rule them all
Re: simple car physics [Re: deathknt] #256022
03/14/09 07:32
03/14/09 07:32
Joined: Jan 2009
Posts: 11
KuRdisTaN - IraQ
dlOvanO Offline OP
Newbie
dlOvanO  Offline OP
Newbie

Joined: Jan 2009
Posts: 11
KuRdisTaN - IraQ
you welcome.....
i wish i be usefull for all


....Never Say I don't Say I'll try....
Re: simple car physics [Re: dlOvanO] #256072
03/14/09 13:00
03/14/09 13:00
Joined: Aug 2008
Posts: 2,838
take me down to the paradise c...
Cowabanga Offline
Expert
Cowabanga  Offline
Expert

Joined: Aug 2008
Posts: 2,838
take me down to the paradise c...
This is the Cardemo physics. But thanks anyway.

Re: simple car physics [Re: Cowabanga] #260366
04/10/09 11:23
04/10/09 11:23
Joined: Jan 2009
Posts: 11
KuRdisTaN - IraQ
dlOvanO Offline OP
Newbie
dlOvanO  Offline OP
Newbie

Joined: Jan 2009
Posts: 11
KuRdisTaN - IraQ
i know that but it's in simple


....Never Say I don't Say I'll try....

Moderated by  HeelX, Spirit 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1