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 ();
}
/******************************************************************************/