Fellow developers, I have made this LEO example to illustrate what is wrong:
// ====================================================================
// This file was generated by LEBuilder
// http://leadwerks.com/werkspace
// ====================================================================
#include "leo.h"
#include <string>
#include <iostream>
using namespace std;
using namespace LEO;
const int ScreenWidth = 800;
const int ScreenHeight = 600;
const char* MediaDir = "C:/Leadwerks Engine SDK";
const char* AppTitle = "Character controller bug?";
const int Group_Normal = 1;
const int Group_Mover = 2;
const int Group_Player = 3;
void ErrOut( const string& message ) { cerr << message << endl; }
// --------------------------------------------
int main( int argc, char* argv[] )
{
// Set graphics mode
Engine engine(AppTitle,ScreenWidth,ScreenHeight);
if( !engine.IsValid() )
{
ErrOut( "Failed to set graphics mode.");
return 1;
}
engine.AddAbstractPath( MediaDir );
// Create framework object and set it to a global object so other scripts can access it
Framework fw;
if( NULL == fw )
{
ErrOut( "Failed to initialize engine." );
return 1;
}
// Set Lua framework object
engine.SetObject( "fw", fw );
// Set Lua framework variable
Lua lua;
lua.PushObject( fw );
lua.SetGlobal( "fw" );
lua.Pop( 1 );
// Get framework main camera
fw.main.GetCamera().SetPosition( Vec3(0,20,-20));
fw.main.GetCamera().SetRotation( Vec3(45,0,0));
// Create cube
TBody cubeBody=CreateBodyBox(2,2,2);
PositionEntity(cubeBody,Vec3(-3,5,-3));
// Create ground
TBody groundBody=CreateBodyBox(20,2,20);
PositionEntity(groundBody,Vec3(0,-3,0));
//Create elevator
TBody elevatorBody=CreateBodyBox(8,2,8);
PositionEntity(elevatorBody,Vec3(0,0,0));
SetBodyGravityMode(elevatorBody,false);
//Create player
TController playerController=CreateController(7.5,1.5,0.5,45,5);
PositionEntity(playerController,Vec3(3,5,3),1);
//Assign types
EntityType(cubeBody,Group_Normal);
EntityType(groundBody,Group_Normal);
EntityType(elevatorBody,Group_Mover);
EntityType(playerController,Group_Player);
//Assign mass
SetBodyMass(groundBody,0);
SetBodyMass(cubeBody,1);
SetBodyMass(elevatorBody,1000);
SetBodyMass(playerController,5);
//Set collisions
SetWorldGravity(Vec3(0,-15,0));
Collisions::Set(Group_Normal,Group_Normal,SLIDINGCOLLISION);
Collisions::Set(Group_Normal,Group_Mover,SLIDINGCOLLISION);
Collisions::Set(Group_Normal,Group_Player,SLIDINGCOLLISION);
Collisions::Set(Group_Mover,Group_Mover,SLIDINGCOLLISION);
Collisions::Set(Group_Mover,Group_Player,SLIDINGCOLLISION);
Collisions::Set(Group_Player,Group_Player,SLIDINGCOLLISION);
DebugPhysics();
// Spin cube until user hits Escape
while( !Keyboard::I****() && !engine.IsTerminated() )
{
if( !engine.IsSuspended() )
{
UpdateWorld();
//Update character controller
float move=(KeyDown(KEY_W)-KeyDown(KEY_S))*10;
float strafe=(KeyDown(KEY_D)-KeyDown(KEY_A))*10;
float jump=0.0;
if (KeyHit(KEY_LSHIFT)) {
if (!ControllerAirborne(playerController)) {
jump=15.0;
}
}
UpdateController(playerController,0.0,move,strafe,jump,20);
//Add mover velocity
if(KeyDown(KEY_LCONTROL)){
AddBodyForce(elevatorBody,Vec3(0,4000,0),1);
}
if(KeyDown(KEY_SPACE)){
AddBodyForce(elevatorBody,Vec3(0,-4000,0),1);
}
if(KeyDown(KEY_RIGHT)){
AddBodyForce(elevatorBody,Vec3(4000,0,0),1);
}
if(KeyDown(KEY_LEFT)){
AddBodyForce(elevatorBody,Vec3(-4000,0,0),1);
}
if(KeyDown(KEY_UP)){
AddBodyForce(elevatorBody,Vec3(0,0,4000),1);
}
if(KeyDown(KEY_DOWN)){
AddBodyForce(elevatorBody,Vec3(0,0,-4000),1);
}
//This fixes the controller
if(KeyDown(KEY_X)){
RotateEntity(playerController,Vec3(0.5,0,0),1);
}
SetBodyTorque(elevatorBody,Vec3(0,0,0),1);
RotateEntity(elevatorBody,Vec3(0,0,0),1);
fw.Update();
fw.Render();
DrawText(20,20,"Use Arrow keys to move platform around, use Ctrl and Space to move up and down");
DrawText(20,40,"Use W,A,S,D to move character controller around. Use LShift to jump");
DrawText(20,60,"Character controller does not move along, press X to apply solution");
engine.Flip(1);
}
}
return engine.Free();
}
Run it and see it yourselves. The character controller does not move accordingly unless it is rotated slightly. dont know if there is another way but that works, for now...
Video of this program in action, I press X on second 60, and you can see it now behaves the way it should. All pressing x does is:
//This fixes the controller
if(KeyDown(KEY_X)){
RotateEntity(playerController,Vec3(0.5,0,0),1);
}
Can this be considered a real bug?