About Store Forum Documentation Contact
Donations:
327$/mo



Post Reply 
character actor.addAccel has no effect on web platform
Author Message
Aimless Offline
Member

Post: #1
character actor.addAccel has no effect on web platform
Hello, i am trying to add gravity for my characters manually and it works as expected in windows build but is not working on web build. It seems that ctrl.actor.addAccel just doesn't do anything. I also tried addForce and addVelocity but they also doesn't do anything in web build.
Code:
Bool GameInit()
{
   Physics.create(EE_PHYSX_DLL_PATH);
   Physics.precision(40);
   Physics.timestep(PHYS_TIMESTEP_ROUND);
   Physics.gravity(Vec(0, -10, 0));
   Physics.simulation_step_completed = GameFixedUpdate;
// ... some other code
   return true;
}

void GameFixedUpdate()
{
   Flt fixed_delta_t = 1.0f / Physics.precision();
   REPA(Players) Players[i].fixed_update(fixed_delta_t);
}

class Player : Game.Chr
{
   virtual void create(Object &obj) override
   {
      super.create(obj);
      ctrl.actor.gravity(false);
   }
  
   void fixed_update(Flt delta_t)
   {
      JavaScriptRun("console.log('fixed update!');"); // this function is called as expected
      if(ctrl.onGround())
         ctrl.actor.addAccel(Vec(0, -20, 0)); // this doesn't work on web
      else
         ctrl.actor.addAccel(Vec(0, -12, 0)); // this doesn't work on web
   }
// ... other code
}
10-19-2017 04:00 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
RE: character actor.addAccel has no effect on web platform
I've just tried this, however it works as expected, when you hold Z, the controller starts to fly up:
Code:
/******************************************************************************
Download EnginePak, ProjectPak;
bool DownloadFinished;
/******************************************************************************/
Actor      ground   ,
           actor[10];
Controller ctrl     ; // controller - it's meant to be used as a 'character actor'
/******************************************************************************/
void Status(C Str &str=S)
{
   JavaScriptRun(S+"Module.setStatus(\""+CString(str)+"\")");
}
/******************************************************************************/
bool Preload()
{
   if(DownloadFinished)return false;
   if(EnginePak.state()==DWNL_DONE && ProjectPak.state()==DWNL_DONE)
   {
      DownloadFinished=true;
      Status("Initializing..");
   }else
   {
      if(! EnginePak.state()) EnginePak.create(EE_ENGINE_PATH);
      if(!ProjectPak.state())ProjectPak.create(EE_PROJECT_PATH);
      
      int done=EnginePak.done()+ProjectPak.done(),
          size=EnginePak.size()+ProjectPak.size();
      Status(S+"Downloading "+(size ? done*100/size : 0)+'%');
   }
   return true;
}
/******************************************************************************/
void PhysicsStep()
{
   if(Kb.b(KB_Z))ctrl.actor.addAccel(Vec(0, 15, 0));
}
void InitPre()
{
#if WEB
   EE_INIT(false, false);
   Paks.addMem( EnginePak.data(),  EnginePak.done());
   Paks.addMem(ProjectPak.data(), ProjectPak.done(), EE_PROJECT_CIPHER);
#else
   EE_INIT();
#endif
   D.mode(800, 600);
   Physics.simulation_step_completed = PhysicsStep;
}
bool Init()
{
   Cam    .dist=4;
   Physics.create(EE_PHYSX_DLL_PATH);
   ground .create(Box(15, 1, 15, Vec(0, -2, 0)), 0);

   // create random actors
   REPA(actor)switch(Random(3))
   {
      case 0: actor[i].create(Box    (RandomF(0.1, 0.5),                    Random(Box(10, 1, 10)))); break;
      case 1: actor[i].create(Ball   (RandomF(0.1, 0.5),                    Random(Box(10, 1, 10)))); break;
      case 2: actor[i].create(Capsule(RandomF(0.1, 0.2), RandomF(0.5, 1.0), Random(Box(10, 1, 10)))); break;
   }

   // create controller
   ctrl.create(Capsule(0.4, 1.7));
   Status();
   return true;
}
/******************************************************************************/
void Shut()
{
}
/******************************************************************************/
bool Update()
{
   if(Kb.bp(KB_ESC))return false;
   Cam.transformByMouse(0.1, 10, CAMH_ZOOM|(Ms.b(1)?CAMH_MOVE:CAMH_ROT)); // move camera on right mouse button

   Physics.startSimulation().stopSimulation();

   // update controller (move on WSAD keys, crouch on Shift key, jump on Space key)
   Flt s=3;
   Vec vel(0, 0, 0);
   if(Kb.b(KB_W))vel+=!PointOnPlane(Cam.matrix.z, Vec(0, 1, 0))*s;
   if(Kb.b(KB_S))vel-=!PointOnPlane(Cam.matrix.z, Vec(0, 1, 0))*s;
   if(Kb.b(KB_A))vel-=!PointOnPlane(Cam.matrix.x, Vec(0, 1, 0))*s;
   if(Kb.b(KB_D))vel+=!PointOnPlane(Cam.matrix.x, Vec(0, 1, 0))*s;
   ctrl.update(vel, Kb.shift(), Kb.bp(KB_SPACE) ? 3.5 : 0);

   return true;
}
/******************************************************************************/
void Draw()
{
   D      .clear();
   Physics.draw ();
}
/******************************************************************************/
10-24-2017 01:13 AM
Find all posts by this user Quote this message in a reply
Aimless Offline
Member

Post: #3
RE: character actor.addAccel has no effect on web platform
Weirdly your sample didn't work either. I found out that this happens only on chrome, firefox runs fine. Probably problem on my side. Will do some more investigation.
Anyways thanks smile

Ok, now i am really confused. I have two monitors, and when i drag my browser window to the secondary monitor everything works, drag it back to primary and it stops working again. (Happens for both chrome and firefox)
My primary monitor is 144Hz maybe that's the culprit.
(This post was last modified: 10-24-2017 06:09 PM by Aimless.)
10-24-2017 05:41 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #4
RE: character actor.addAccel has no effect on web platform
Yes, I think the higher refresh rate could be the reason.. Let me try to investigate.
10-24-2017 10:55 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #5
RE: character actor.addAccel has no effect on web platform
I think I've found the source of the problem, let me try to solve it..
10-24-2017 11:36 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #6
RE: character actor.addAccel has no effect on web platform
I think this will work in next release. Once the engine is updated in the future, please try.
Thank you for reporting the problem.

Also instead of doing:
Flt fixed_delta_t = 1.0f / Physics.precision();
please use:
Flt fixed_delta_t = Physics.stepTime or Physics.time (this will be available in next release)
10-25-2017 05:37 AM
Find all posts by this user Quote this message in a reply
Aimless Offline
Member

Post: #7
RE: character actor.addAccel has no effect on web platform
Thanks, it seems working now.
11-09-2017 09:08 AM
Find all posts by this user Quote this message in a reply
Post Reply