About Store Forum Documentation Contact
Donations:
327$/mo



Post Reply 
New SimpleVehicle class
Author Message
Esenthel Offline
Administrator

Post: #16
RE: New SimpleVehicle class
(04-12-2013 10:25 PM)Ezequel Wrote:  Will there be a tutorial for this?

This will be in next release:
Code:
/******************************************************************************/
Memc<Actor>   actors;
SimpleVehicle vehicle;
/******************************************************************************/
void InitPre()
{
   EE_INIT();
   App.flag=APP_RESIZABLE|APP_MINIMIZABLE|APP_MAXIMIZABLE|APP_WORK_IN_BACKGROUND|AP​P_FULL_TOGGLE;
#ifdef DEBUG
   App.flag|=APP_MEM_LEAKS|APP_BREAKPOINT_ON_ERROR;
#endif
   Cam.dist=10;
   Cam.pitch=-0.4;
   D.viewFov(DegToRad(60)).mode(App.desktopW()*0.8, App.desktopH()*0.8);
}
/******************************************************************************/
bool Init()
{
   Physics.create(EE_PHYSX_DLL_PATH);

   actors.New().create(Plane(Vec(0, -1, 0), Vec(0, 1, 0))); // create ground

   SimpleVehicle.Params params; // setup vehicle params
   flt x=0.9, y=-0.5, z=1.8;
   params.wheel[WHEEL_LEFT_FRONT ].pos.set(-x, y,  z);
   params.wheel[WHEEL_RIGHT_FRONT].pos.set( x, y,  z);
   params.wheel[WHEEL_LEFT_REAR  ].pos.set(-x, y, -z);
   params.wheel[WHEEL_RIGHT_REAR ].pos.set( x, y, -z);
   PhysBody body; body.parts.New().create(Box(2, 1, 4)); body.setBox(); // create vehicle body
   vehicle.create(body, params, 1, 1); // create vehicle

   return true;
}
/******************************************************************************/
void Shut()
{
}
/******************************************************************************/
bool Update()
{
   if(Kb.bp(KB_ESC))return false;
   Physics.startSimulation().stopSimulation(); // update physics

   // set vehicle input
   flt forward=Kb.b(KB_W),
       back   =Kb.b(KB_S),
       angle  =Kb.b(KB_D)-Kb.b(KB_A);

   flt accel, brake;
   if(vehicle.speed()<=1 && back>forward) // if moving at slow speed and want to go backward
   {
      accel=-back   ; // set negative acceleration
      brake= forward; // set braking
   }else
   {
      accel=forward;
      brake=back;
   }

   vehicle.angle(angle).accel(accel).brake(brake);

   // setup camera
   Cam.at =vehicle.pos();
   Cam.yaw=Angle(vehicle.matrix().z.xz())-PI_2;
   Cam.setSpherical().updateVelocities(CAM_ATTACH_ACTOR).set();

   return true;
}
/******************************************************************************/
void Draw()
{
   D.clear(TURQ);
   Physics.draw();
  
   // draw wheels
   SetMatrix();
   REP(WHEEL_NUM)
   {
      WHEEL_TYPE wheel =WHEEL_TYPE(i);
      Matrix     matrix=vehicle.wheelMatrix(wheel); matrix.draw();
      Tube(vehicle.wheelRadius(wheel), 0.2, matrix.pos, matrix.x).draw();
   }
}
/******************************************************************************/

Quote:When the vehicle flips over, will it always flip back on its wheels like in the video?

That's not guaranteed.

Quote:I'm already playing with this, but i'm not able to push other physical bodies around
Please insert into above tutorial code this line to the Init function
Code:
actors.New().create(Box(1, 1, 1, Vec(0, 0, 2)));
for me it works fine.

Quote:if I just use vehicle.mass() and set it to some non 0 value the vehicle simulation breaks.
I recommend controlling vehicle mass through density parameter in the 'create' method.
However I've tried changing its mass during the simulation with
Code:
if(Kb.bp(KB_LCTRL))vehicle.mass(vehicle.mass()*2);
and it works fine, perhaps you've set the mass too big or too small somehow.
04-13-2013 12:09 PM
Find all posts by this user Quote this message in a reply
candam Offline
Member

Post: #17
RE: New SimpleVehicle class
It's so impressive nice physics that you got over there grin
04-13-2013 12:11 PM
Find all posts by this user Quote this message in a reply
para Offline
Member

Post: #18
RE: New SimpleVehicle class
My issue was related to the actor body, it was a convex hull translated at min y = 0, possibly even scaled..for some reason it worked ok with regular vehicle class.. I made a new convex body and now all is working fine.

Quote:It's so impressive nice physics that you got over there
I agree, the driving is very satisfactory and a nice addition to the engine.

Looking forward to the new game!
04-16-2013 01:45 AM
Visit this user's website Find all posts by this user Quote this message in a reply
SamerK Offline
Member

Post: #19
RE: New SimpleVehicle class
very smooth physics, another great addition to EE.
in the video (0.38) I liked how smoothly the vehicle drifted and entered the gate .

Many Thanks..
10-09-2013 03:12 PM
Find all posts by this user Quote this message in a reply
Post Reply