Ok, so I've create a component::CharacterController, basically it's just this :
- Code: Select all
void CharacterController::_CreateCharacter()
{
physics::Scene* scene = GetNode().GetRoot().FindComponent<physics::Scene>();
_PlayerController = COFFEE_New(CustomPlayerController);
_PlayerController->m_body = GetNode().GetRigidBody()._Body;
_PlayerController->m_world = scene->GetWorld();
_PlayerController->Init(PLAYER_MASS, 1.0f, 1.0f, 2.0f, 0.7f, GetIdentityMatrix());
_PlayerController->SetRestrainingDistance(0.1f);
GetNode().GetTransform().SetTranslation(basic::Vector3(0.0f, 10.0f, 0.0f));
}
#define PLAYER_MASS 80.0f
#define PLAYER_WALK_SPEED 4.0f
void CharacterController::OnFixedUpdate(const basic::Time& time_step)
{
if (GetNode().HasRigidBody() && GetNode().GetRigidBody().IsRunning())
{
if (_PlayerController==NULL)
{
_CreateCharacter();
}
else
{
dFloat forwarSpeed = (int (input::Keyboard::Get().IsButtonPressed(input::KEY_Up))
- int (input::Keyboard::Get().IsButtonPressed(input::KEY_Down))) * PLAYER_WALK_SPEED;
dFloat strafeSpeed = (int (input::Keyboard::Get().IsButtonPressed(input::KEY_Right))
- int (input::Keyboard::Get().IsButtonPressed(input::KEY_Left))) * PLAYER_WALK_SPEED;
// normalize player speed
dFloat mag2 = forwarSpeed * forwarSpeed + strafeSpeed * strafeSpeed;
if (mag2 > 0.0f) {
dFloat invMag = PLAYER_WALK_SPEED / dSqrt (mag2);
forwarSpeed *= invMag;
strafeSpeed *= invMag;
}
dVector gravity(0.0f, -9.81f, 0.0f, 0.0f);
_PlayerController->SetPlayerVelocity(
forwarSpeed,
strafeSpeed,
0.0f,
0.0f,
gravity,
time_step.GetSecondCount());
_PlayerController->PostUpdate(time_step.GetSecondCount(), 0);
}
}
}
Creation goes well, it tries to update, but then there is a bug, here is kind of callstack, but the reason is obvious:
- Code: Select all
CustomPlayerController::UpdateGroundPlane
NewtonWorldConvexRayCast
dgBroadPhase::ConvexRayCast
dgBody::ConvexRayCast
dgCollisionInstance::ConvexRayCast
dgAssert (0);
m_scaleIsUnit is false, because I use a non-uniform scaled box as ground, since I like it you know

...Else I'm happy to get here tonight, just some points through :
- there is a CustomPlayerControllerManager, for now it's only used to get the NewtonWorld and an empty callback about contacts, I think you have ideas about extending it later on, but do I really require this or I may just use the PlayerController alone ? In my sample I just added a m_World member to override controller, for now.
- preupdate() and postupdate() methods, why not only update() ? (not a big deal, just want to be sure / not confused)
- I've already a FreeController with free move & collisions support, rotation / lookat is handled at full fps in the update() method, while translation is handled by physics in the fixed_update() / fixedtimestep method, I plan to do the same thing with your controller, do you use/need the correct rotation somewhere or I may just don't care ?
Thanks, I'm on the right track now !
edit: Oh, and I planned to do the Ludum Dare next week-end, basically it'll be game based on non-uniform scaled cubes with some Newton basic physics and some audio... I hope to get that controller working, in bad case I'll use the other, but I've lot of other things to do & test you know

It'll be used as a demo & test case for my project, so it'll be upgraded later on as well, I will share the resulting thing here.