Advertisement
Guest User

Untitled

a guest
Jan 30th, 2013
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.73 KB | None | 0 0
  1. var video_mode = 7;
  2. var video_depth = 32;
  3. // Car Simple Physics
  4. // Base code written by William
  5. // Edited and tweaked by Dennis_fantasy
  6. // Thanks to Realspawn
  7.  
  8. //Variables
  9.  
  10. //Wheels & chassis Defines
  11. entity* wheel_fr;
  12. entity* wheel_fl;
  13. entity* wheel_bl;
  14. entity* wheel_br;
  15. entity* chassis;
  16.  
  17. var FR_wheel_ID;
  18. var FL_wheel_ID;
  19. var RL_wheel_ID;
  20. var RR_wheel_ID;
  21. var CHASSIS_ID;
  22.  
  23. var p1[3];
  24. var p2[3];
  25. var p3[3];
  26. var p4[3];
  27. var p5[3];
  28. var p6[3];
  29.  
  30. //Environment Defines
  31. var earth_gravity[3] = 0,0, -886;
  32.  
  33. var wheel_mass = 60;
  34. var wheel_friction = 100;
  35. var wheel_bounciness = 25;
  36. var wheel_minimumSpeed = 5;
  37.  
  38. var kart_mass = 50;
  39. var kart_friction = 15;
  40. var kart_bounciness = 5;
  41. var kart_minimumSpeed = 5;
  42.  
  43.  
  44. //Movement Defines
  45. var m1_1[3];
  46. var m1_2[3];
  47. var m2[3];
  48. var wheel_target;
  49.  
  50. //Chassis Settings
  51.  
  52. action chassis_carro
  53. {
  54. chassis = me;
  55.  
  56. my.shadow = on;
  57.  
  58. phent_settype(my,PH_RIGID,PH_box);
  59.  
  60. chassis.overlay = off;
  61. chassis.flare = off;
  62. chassis.bright = off;
  63. chassis.transparent = off;
  64. chassis.ambient = 50;
  65.  
  66. my.fat = on;
  67.  
  68. ph_setgravity(earth_gravity);
  69. phent_setgroup(my,2);
  70. phent_setmass(my,kart_mass,PH_box);
  71. phent_setfriction(my,kart_friction);
  72. phent_setelasticity(my,kart_bounciness,kart_minimumspeed);
  73.  
  74. vec_set(p2,vector(1,1,1));
  75. vec_set(p3,vector(0,1,0));
  76. vec_set(p4,vector(360,-360,360));
  77. vec_set(p6,vector(0,0,0));
  78.  
  79. phcon_setparams1(CHASSIS_ID,my.x,p2,p3);
  80. phcon_setparams2(CHASSIS_ID,p4,nullvector,p6);
  81.  
  82. ph_setgravity(vector(0,0,-380));
  83. ph_setcorrections(30000,0.05);
  84.  
  85. control();
  86. }
  87.  
  88. //FrontLeft Wheel
  89.  
  90. action fl_wheel
  91. {
  92. wheel_FL=my;
  93.  
  94. my.shadow = on;
  95. my.narrow = on;
  96.  
  97.  
  98. phent_settype(my,PH_RIGID,PH_sphere);
  99.  
  100. phent_setgroup(my,2);
  101. phent_setmass(my,wheel_mass,PH_sphere);
  102.  
  103. phent_setfriction(my,wheel_friction);
  104. phent_setelasticity(my,wheel_bounciness ,wheel_minimumSpeed);
  105. phent_setdamping(my,20,20);
  106.  
  107. vec_set(p2,vector(0,0,1));
  108. vec_set(p3,vector(0,1,0));
  109. vec_set(p4,vector(-40,40,0));
  110. vec_set(p6,vector(0,0,0));
  111. FL_wheel_ID=phcon_add(PH_WHEEL,chassis,my);
  112. phcon_setparams1(FL_wheel_ID,my.x,p2,p3);
  113. phcon_setparams2(FL_wheel_ID,p4,nullvector,p6);
  114. }
  115.  
  116. //FrontRight Wheel
  117.  
  118. action fr_wheel//front right tire
  119. {
  120. wheel_FR=my;
  121.  
  122. my.shadow = on;
  123. my.narrow = on;
  124.  
  125.  
  126. phent_settype(my,PH_RIGID,PH_sphere);
  127.  
  128. phent_setgroup(my,2);
  129. phent_setmass(my,wheel_mass,PH_sphere);
  130.  
  131. phent_setfriction(my,wheel_friction);
  132. phent_setelasticity(my,wheel_bounciness ,wheel_minimumSpeed);
  133. phent_setdamping(my,20,20);
  134.  
  135. vec_set(p2,vector(0,0,1));
  136. vec_set(p3,vector(0,1,0));
  137. vec_set(p4,vector(-40,40,0));
  138. vec_set(p6,vector(0,0,0));
  139. FR_wheel_ID=phcon_add(PH_WHEEL,chassis,my);
  140. phcon_setparams1(FR_wheel_ID,my.x,p2,p3);
  141. phcon_setparams2(FR_wheel_ID,p4,nullvector,p6);
  142. }
  143.  
  144. //BackLeft Wheel
  145.  
  146. action bl_wheel //back left tire
  147. {
  148. wheel_bL=my;
  149.  
  150. my.shadow = on;
  151. my.narrow = on;
  152.  
  153.  
  154. phent_settype(my,PH_RIGID,PH_sphere);
  155.  
  156. phent_setgroup(my,2);
  157. phent_setmass(my,wheel_mass,PH_sphere);
  158.  
  159. phent_setfriction(my,wheel_friction);
  160. phent_setelasticity(my,wheel_bounciness ,wheel_minimumSpeed);
  161. phent_setdamping(my,20,20);
  162.  
  163. vec_set(p2,vector(0,0,1));
  164. vec_set(p3,vector(0,1,0));
  165. vec_set(p4,vector(0,0,0));
  166. vec_set(p6,vector(0,0,0));
  167. RL_wheel_ID=phcon_add(PH_WHEEL,chassis,my);
  168. phcon_setparams1(RL_wheel_ID,my.x,p2,p3);
  169. phcon_setparams2(RL_wheel_ID,p4,nullvector,p6);
  170. }
  171.  
  172. //BackRight Wheel
  173.  
  174. action br_wheel
  175. {
  176. wheel_bR=my;
  177.  
  178. my.shadow = on;
  179. my.narrow = on;
  180.  
  181.  
  182. phent_settype(my,PH_RIGID,PH_sphere);
  183.  
  184. phent_setgroup(my,2);
  185. phent_setmass(my,wheel_mass,PH_sphere);
  186.  
  187. phent_setfriction(my,wheel_friction);
  188. phent_setelasticity(my,wheel_bounciness ,wheel_minimumSpeed);
  189. phent_setdamping(my,20,20);
  190.  
  191. vec_set(p2,vector(0,0,1));
  192. vec_set(p3,vector(0,1,0));
  193. vec_set(p4,vector(0,0,0));
  194. vec_set(p6,vector(0,0,0));
  195. RR_wheel_ID=phcon_add(PH_WHEEL,chassis,my);
  196. phcon_setparams1(RR_wheel_ID,my.x,p2,p3);
  197. phcon_setparams2(RR_wheel_ID,p4,nullvector,p6);
  198. }
  199.  
  200. //Control input
  201.  
  202. function main()
  203. {
  204. level_load ("level.wmb");
  205. wait(2);
  206. }
  207. function control
  208. {
  209. while(1)
  210. {
  211. if(key_a == 1)
  212. {
  213. wheel_target=-30;
  214. }
  215. if(key_d == 1)
  216. {
  217. wheel_target= 30;
  218. }
  219. if(key_a == 1 && key_d == 1)||(key_a == 0 && key_d == 0)
  220. {
  221. wheel_target=0;
  222. }
  223. if(key_s == 1)
  224. {
  225. vec_set(m2,vector(600,800,0));
  226. }
  227. if(key_w == 1)
  228. {
  229. vec_set(m2,vector(-600,800,0));
  230. }
  231. if(key_s == 1 && key_w == 1)||(key_s == 0 && key_w == 0)
  232. {
  233. vec_set(m2,vector(0,0,0));
  234. }
  235.  
  236. if(key_space == 1)
  237. {
  238. vec_set(m2,vector(0,-1500,0));
  239. }
  240. if(key_shift == 1)
  241. {
  242. vec_set(m2,vector(200,1200,0));
  243. }
  244.  
  245. phcon_getposition(FR_wheel_ID,temp);
  246. vec_set(m1_1,vector((wheel_target-temp.x)*0.9,500,500));
  247.  
  248. phcon_getposition(FL_wheel_ID,temp);
  249. vec_set(m1_2,vector((wheel_target-temp.x)*0.9,500,500));
  250.  
  251. phcon_setmotor(FR_wheel_ID,m1_1,m2,nullvector);
  252. phcon_setmotor(FL_wheel_ID,m1_2,m2,nullvector);
  253. phcon_setmotor(RR_wheel_ID,nullvector,m2,nullvector);
  254. phcon_setmotor(RL_wheel_ID,nullvector,m2,nullvector);
  255.  
  256. wait(1);
  257. }
  258. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement