I am new to Newton and I'm evaluating it for use in my game engine. I like what I see so far in terms of accuracy / stability versus Bullet etc. plus I see the development and forums are very active, but I'm having a few troubles that I haven't been able to work out on my own so far and I was hoping that I could get some help here.
I am trying to construct a basic scenario where there is a falling box and a first person controller that allows you to navigate the environment, jump on, and push the box.
I started to write a kinematic character controller. Once I had the basics up and running I observed that the camera wasn't at the correct height. In the documentation it said that the capsule was along the X axis, so I use a rotation for the offset matrix along the z axis.
If I didn't apply the rotation, the camera was at exactly the capsule radius off the ground. If I rotated the collision any amount (even a random value) along the Z axis however I was getting the same incorrect height.
- Code: Select all
//90 degrees rotation along the z axis, should make capsule upright
dQuaternion capsuleRot(dVector(0.0,0.0,1.0), 3.14 / 2.0);
dMatrix offsetMat = dMatrix(capsuleRot, dVector(0,0,0));
y = 5.0;
capsuleCollision = NewtonCreateCapsule(g_world, playerRadius, playerHeight, PLAYER_ID, offsetMat.data());
I was able to solve this problem and get the correct capsule rotation by applying the rotation directly to the body with
- Code: Select all
NewtonCreateKinematicBody(g_world, capsuleCollision, &playerMatrix[0][0]);
It seems counterintuitive that I can't apply the rotation directly to the collision shape; in this instance I want to use a vertical capsule as the bounding volume for the character. Do I have a conceptual misunderstanding of what's going on here? Is this the best way to achieve what I want?
Additionally, I wanted to compare the feel of a kinematic character controller with one created using a dynamics object where the instantaneous velocity is set whenever the movement keys are pressed.
This required adding a constraint to the character to keep it upright, using the following:
- Code: Select all
dVector upDirection (0.0f, 1.0f, 0.0f);
upVector = NewtonConstraintCreateUpVector (g_world , &upDirection.m_x, playerBody);
I was unable to find any further instructions indicating another step is required.
However, this seems to have no effect whatsoever. I even made the player object a box with no rotation applied just to be safe. When I start my demo the camera is at the correct height then my falling box hits the player and knocks them over flat on their back. Is the up vector constraint still supported? Or is there some other requirement I'm not meeting?
I would appreciate any answers to these questions, and I look forward to working with Newton.
-Chris