Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var video_mode = 7;
- var video_depth = 32;
- // Car Simple Physics
- // Base code written by William
- // Edited and tweaked by Dennis_fantasy
- // Thanks to Realspawn
- //Variables
- //Wheels & chassis Defines
- entity* wheel_fr;
- entity* wheel_fl;
- entity* wheel_bl;
- entity* wheel_br;
- entity* chassis;
- var FR_wheel_ID;
- var FL_wheel_ID;
- var RL_wheel_ID;
- var RR_wheel_ID;
- var CHASSIS_ID;
- var p1[3];
- var p2[3];
- var p3[3];
- var p4[3];
- var p5[3];
- var p6[3];
- //Environment Defines
- var earth_gravity[3] = 0,0, -886;
- var wheel_mass = 60;
- var wheel_friction = 100;
- var wheel_bounciness = 25;
- var wheel_minimumSpeed = 5;
- var kart_mass = 50;
- var kart_friction = 15;
- var kart_bounciness = 5;
- var kart_minimumSpeed = 5;
- //Movement Defines
- var m1_1[3];
- var m1_2[3];
- var m2[3];
- var wheel_target;
- //Chassis Settings
- action chassis_carro
- {
- chassis = me;
- my.shadow = on;
- phent_settype(my,PH_RIGID,PH_box);
- chassis.overlay = off;
- chassis.flare = off;
- chassis.bright = off;
- chassis.transparent = off;
- chassis.ambient = 50;
- my.fat = on;
- ph_setgravity(earth_gravity);
- phent_setgroup(my,2);
- phent_setmass(my,kart_mass,PH_box);
- phent_setfriction(my,kart_friction);
- phent_setelasticity(my,kart_bounciness,kart_minimumspeed);
- vec_set(p2,vector(1,1,1));
- vec_set(p3,vector(0,1,0));
- vec_set(p4,vector(360,-360,360));
- vec_set(p6,vector(0,0,0));
- phcon_setparams1(CHASSIS_ID,my.x,p2,p3);
- phcon_setparams2(CHASSIS_ID,p4,nullvector,p6);
- ph_setgravity(vector(0,0,-380));
- ph_setcorrections(30000,0.05);
- control();
- }
- //FrontLeft Wheel
- action fl_wheel
- {
- wheel_FL=my;
- my.shadow = on;
- my.narrow = on;
- phent_settype(my,PH_RIGID,PH_sphere);
- phent_setgroup(my,2);
- phent_setmass(my,wheel_mass,PH_sphere);
- phent_setfriction(my,wheel_friction);
- phent_setelasticity(my,wheel_bounciness ,wheel_minimumSpeed);
- phent_setdamping(my,20,20);
- vec_set(p2,vector(0,0,1));
- vec_set(p3,vector(0,1,0));
- vec_set(p4,vector(-40,40,0));
- vec_set(p6,vector(0,0,0));
- FL_wheel_ID=phcon_add(PH_WHEEL,chassis,my);
- phcon_setparams1(FL_wheel_ID,my.x,p2,p3);
- phcon_setparams2(FL_wheel_ID,p4,nullvector,p6);
- }
- //FrontRight Wheel
- action fr_wheel//front right tire
- {
- wheel_FR=my;
- my.shadow = on;
- my.narrow = on;
- phent_settype(my,PH_RIGID,PH_sphere);
- phent_setgroup(my,2);
- phent_setmass(my,wheel_mass,PH_sphere);
- phent_setfriction(my,wheel_friction);
- phent_setelasticity(my,wheel_bounciness ,wheel_minimumSpeed);
- phent_setdamping(my,20,20);
- vec_set(p2,vector(0,0,1));
- vec_set(p3,vector(0,1,0));
- vec_set(p4,vector(-40,40,0));
- vec_set(p6,vector(0,0,0));
- FR_wheel_ID=phcon_add(PH_WHEEL,chassis,my);
- phcon_setparams1(FR_wheel_ID,my.x,p2,p3);
- phcon_setparams2(FR_wheel_ID,p4,nullvector,p6);
- }
- //BackLeft Wheel
- action bl_wheel //back left tire
- {
- wheel_bL=my;
- my.shadow = on;
- my.narrow = on;
- phent_settype(my,PH_RIGID,PH_sphere);
- phent_setgroup(my,2);
- phent_setmass(my,wheel_mass,PH_sphere);
- phent_setfriction(my,wheel_friction);
- phent_setelasticity(my,wheel_bounciness ,wheel_minimumSpeed);
- phent_setdamping(my,20,20);
- vec_set(p2,vector(0,0,1));
- vec_set(p3,vector(0,1,0));
- vec_set(p4,vector(0,0,0));
- vec_set(p6,vector(0,0,0));
- RL_wheel_ID=phcon_add(PH_WHEEL,chassis,my);
- phcon_setparams1(RL_wheel_ID,my.x,p2,p3);
- phcon_setparams2(RL_wheel_ID,p4,nullvector,p6);
- }
- //BackRight Wheel
- action br_wheel
- {
- wheel_bR=my;
- my.shadow = on;
- my.narrow = on;
- phent_settype(my,PH_RIGID,PH_sphere);
- phent_setgroup(my,2);
- phent_setmass(my,wheel_mass,PH_sphere);
- phent_setfriction(my,wheel_friction);
- phent_setelasticity(my,wheel_bounciness ,wheel_minimumSpeed);
- phent_setdamping(my,20,20);
- vec_set(p2,vector(0,0,1));
- vec_set(p3,vector(0,1,0));
- vec_set(p4,vector(0,0,0));
- vec_set(p6,vector(0,0,0));
- RR_wheel_ID=phcon_add(PH_WHEEL,chassis,my);
- phcon_setparams1(RR_wheel_ID,my.x,p2,p3);
- phcon_setparams2(RR_wheel_ID,p4,nullvector,p6);
- }
- //Control input
- function main()
- {
- level_load ("level.wmb");
- wait(2);
- }
- function control
- {
- while(1)
- {
- if(key_a == 1)
- {
- wheel_target=-30;
- }
- if(key_d == 1)
- {
- wheel_target= 30;
- }
- if(key_a == 1 && key_d == 1)||(key_a == 0 && key_d == 0)
- {
- wheel_target=0;
- }
- if(key_s == 1)
- {
- vec_set(m2,vector(600,800,0));
- }
- if(key_w == 1)
- {
- vec_set(m2,vector(-600,800,0));
- }
- if(key_s == 1 && key_w == 1)||(key_s == 0 && key_w == 0)
- {
- vec_set(m2,vector(0,0,0));
- }
- if(key_space == 1)
- {
- vec_set(m2,vector(0,-1500,0));
- }
- if(key_shift == 1)
- {
- vec_set(m2,vector(200,1200,0));
- }
- phcon_getposition(FR_wheel_ID,temp);
- vec_set(m1_1,vector((wheel_target-temp.x)*0.9,500,500));
- phcon_getposition(FL_wheel_ID,temp);
- vec_set(m1_2,vector((wheel_target-temp.x)*0.9,500,500));
- phcon_setmotor(FR_wheel_ID,m1_1,m2,nullvector);
- phcon_setmotor(FL_wheel_ID,m1_2,m2,nullvector);
- phcon_setmotor(RR_wheel_ID,nullvector,m2,nullvector);
- phcon_setmotor(RL_wheel_ID,nullvector,m2,nullvector);
- wait(1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement