Character Controller

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Character Controller

Postby Erica Woodhull » Thu Aug 11, 2011 2:47 am

Hi everybody,
I am developing a first person shooter using my own 3d engine (the SoftPixel Engine) and NewtonGameDynamics.
But before I can integrate the PhysicsEngine in my GameEngine I have to make some tests in seperated small programs to see, how I have to use Newton SDK for things like the character controller.
I know there is an example in the new SDK but it is not so easy for my to comprehend the source code (of the Tutorial).
I hope it is not so difficult to write a character controller so that Newton assumes already the most work - programmers are lazy ^^

Currently I make it wrong well, I use NewtonUpVectorSetPin function to set the player upright.
But to walk I just the NewtonBodySetVelocity function. This do not work really nice. Maybe I have some wrong parameters set to the material.
I also use the capsule for the player.

My concrete question is, what are the main functions and main technics for a character controller?
Thank you once already in advance.

























Image
----------------------------------------------------------
wii controller
classic wii controller
wii controller
nintendo wii controller
Erica Woodhull
 

Re: Character Controller

Postby JoeJ » Thu Aug 11, 2011 4:29 am

As far as i know the UpVector and other build in joints are declared depracated, and Julio recommends to use the UserJoint.
Usage Examples are in dCustomJoints, includes more complex Character Controller too.
At first that looked complicatet to me, but after playing around they are very easy to use and allow more possibilities than seen in any other physics engine.

To do your own up vector, create the Joint...
Code: Select all
NewtonJoint* joint = NewtonConstraintCreateUserJoint (world, /*numberOfMaximalRows = */4, MyCallback, 0, /*childBody = */capsule,/* parentBody = */0);
NewtonJointSetUserData (joint, &myData);


Then in your Callback you can apply the constraint...
Code: Select all
void MyCallback (const NewtonJoint* joint, float timestep, int threadIndex)
{
// up vector...
   MyData* data= (MyData*) NewtonJointGetUserData (joint);
   NewtonBody* body = data->body;
NewtonBodyGetMatrix (body, matrix);
vec3 axis; float angle;
CalcAxisAndAngleBetweenVectors (vec3 (0,1,0)/*upwards*/, matrix.upAxisVector, axis, angle);
NewtonUserJointAddAngularRow (joint, angle, (float*)&axis); // fix angular alignment

// you can do more things here, f.ex. constrain position to allow movement only up / downwards if on a ladder... but don't forget to increment numberOfMaximalRows for each added Row


// position for movement (optional)...

NewtonUserJointAddLinearRow (joint, (float*)&matrix.pos, (float*)&data->targetPos, (float*)&vec3(1,0,0));
NewtonUserJointAddLinearRow (joint, (float*)&matrix.pos, (float*)&data->targetPos, (float*)&vec3(0,1,0));
NewtonUserJointAddLinearRow (joint, (float*)&matrix.pos, (float*)&data->targetPos, (float*)&vec3(0,0,1)); // fix positional displacement in all dimensions
// you may want to limit maximum forces for this point to point constraint using NewtonUserJointSetRowMinimum+MaximumFriction () after each Row
}


It might be better to handle movement in force and torque callback, like you actually do.
But see there: http://newtondynamics.com/forum/viewtopic.php?f=9&t=6722

EDIT:
You could handle the orientation (look at + up vector) in f+t callback aswell avoiding any joint,
personally i'd try that first for that purpose, since a player is not constrained in space so hard.
Using axis and angle as above, you can calculate angular velocity to rotate the body upright until the next frame, convert to torque and apply it.
Angvel to torque conversation is covered here: http://newtondynamics.com/forum/viewtopic.php?f=9&t=6570&p=46210#p46210
User avatar
JoeJ
 
Posts: 1489
Joined: Tue Dec 21, 2010 6:18 pm


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest