Newton Character Controller

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Newton Character Controller

Postby Leadwerks » Sun Jan 08, 2017 12:14 pm

I am starting a new thread to discuss the Newton character controller. I would like to move to this, but presently it has problems preventing me from using it.

Our present character controller is rather slow and it tends to be a bottleneck when large numbers of enemies are active. This is as much as we can do at 30 FPS, which is quite good:


But the renderer can handle a lot more than that:


Has any progress been made on the character controller problems I described? We are through the Christmas rush and I am starting a new dev cycle. Ideally I would like to release a new version with updated character controller physics on April 1.
User avatar
Leadwerks
 
Posts: 569
Joined: Fri Oct 27, 2006 2:54 pm

Re: Newton Character Controller

Postby godlike » Mon Jan 09, 2017 7:22 am

Just want to say that I'm very interested in having a robust character controller as well. Will mention my problems:
- On stairs, for example, the movement is not smooth. Probably because the inner shape is a cylinder. Maybe a capsule will be better but I'm not sure. I've tried replacing it to a capsule some time ago and it wasn't thaaat better.
- On other rough surfaces with small polygons the controller jumps around.

Maybe using different shapes will do the trick. What about 2 spheres (like a snowman)? That will probably create smooth motion and it will probably be faster for Leadwerks' needs (sphere collision AFAIK is faster).
User avatar
godlike
 
Posts: 58
Joined: Sun Mar 16, 2014 3:48 am

Re: Newton Character Controller

Postby JoeJ » Mon Jan 09, 2017 8:41 am

You could fix jumpy vertical motion by a temporal filtered offset for the camera making it follow smoothly.
User avatar
JoeJ
 
Posts: 1453
Joined: Tue Dec 21, 2010 6:18 pm

Re: Newton Character Controller

Postby JoeJ » Mon Jan 09, 2017 8:58 am

Im curious why you guys use a character controller at all.

Personally i have just a capsule (regular dynamic body) with upvector constraint that i move by forces.
This does not have any of the mentioned problems, but also it does not have the ability to stop the player walking over a cliff to death.

But that's the only example i can think of, so what other functionality of a advanced character controller do you expect to be usefull for gameplay?
User avatar
JoeJ
 
Posts: 1453
Joined: Tue Dec 21, 2010 6:18 pm

Re: Newton Character Controller

Postby godlike » Mon Jan 09, 2017 9:18 am

JoeJ wrote:Im curious why you guys use a character controller at all.

Personally i have just a capsule (regular dynamic body) with upvector constraint that i move by forces.
This does not have any of the mentioned problems, but also it does not have the ability to stop the player walking over a cliff to death.

But that's the only example i can think of, so what other functionality of a advanced character controller do you expect to be usefull for gameplay?


For a first-person character controller the movement doesn't quite obey the laws of physics. The movement has to be snappy that's why there is no acceleration. The velocity is always constant.

Is that possible with the method you are describing?
User avatar
godlike
 
Posts: 58
Joined: Sun Mar 16, 2014 3:48 am

Re: Newton Character Controller

Postby Julio Jerez » Mon Jan 09, 2017 9:56 am

godlike, can you provide a test case that I can use for adding that functionality?

like you said player controllers is no something you do using equation of physics, is more an ad-hoc system base on heuristics.

the player controller in the joint library passes the test that are in the demos. I can see how it will faill on other citations but each time people has a complain or a bug, I only get vague description, then I do what I can and then there is never a follow up.

I know the play controller need a revamp and there many new functionality in 3.14 to fix it.
the problem is that is I rewrite it, there is a high chance that the behavior will be almost identical to what the one is in because this is what I understand a controller should be.

what I need is a test case, that some one added either the demos of a standalone demo linked to the newton DLL so that I can use as the goal.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Newton Character Controller

Postby godlike » Mon Jan 09, 2017 10:22 am

Julio Jerez wrote:godlike, can you provide a test case that I can use for adding that functionality?

the player controller in the joint library passes the test that are in the demos. I can see how it can fail on other citations but each time people has a complain or a bug, I only get vague description, then I do what I can and then there is never a follow up.


You are right on that. We need to follow up on our requests.

To cut to the chase, I can provide multiple things but I need to know what will work for you better. For example, I can give you an executable and some assets and you can run this demo https://www.youtube.com/watch?v=va7nZ2EFR4c. You can visualize the collision geometry also.

I can also give you the full source and you can compile it yourself.

Maybe something else? Let me know.
User avatar
godlike
 
Posts: 58
Joined: Sun Mar 16, 2014 3:48 am

Re: Newton Character Controller

Postby Julio Jerez » Mon Jan 09, 2017 11:29 am

oh yes an executable linked to teh debug newton dll running the demo in the you tube video would be ideal.
is that demo running the newton player or something else?
if is running the newton Player controller then that's all I need. we can start from there.''an we cna move on stages.
-first fix the bugs.
-add basic functionality and make robust and versatile and fast.

since we are going to revamp the player, we can also discuss the design, for what I can see people do not really like the top capsule mounted on a thin cylinder. must prefer a simple capsule. I can understand that.

one of the reason the player was like that was to make up for lack of the aspect ratio of the capsule shape offer, but now that we have full non uniform scale we can use a single capsule with a non uniform scale that will keep the same aspect ratio at any player size, the same way vehicle ire are made.
this will make much faster as well since capsule vs any shape is perhaps the faster collision shape in the engine.
Also you guys can list the specification so that we can have a common technical design doc to guide us.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Newton Character Controller

Postby godlike » Mon Jan 09, 2017 12:01 pm

Julio Jerez wrote:oh yes an executable linked to teh debug newton dll running the demo in the you tube video would be ideal.
is that demo running the newton player or something else?


Cool. Please allow me some time to do that. First I need to upgrade to newer Newton but I need to see why Newton build is failing first (Newton's Linux build is broken ATM and that will break my stuff). I'm not using Newton's controller, I need do some modifications for that (currently I've copied Newton's controller and adapted it a bit).
User avatar
godlike
 
Posts: 58
Joined: Sun Mar 16, 2014 3:48 am

Re: Newton Character Controller

Postby JoeJ » Mon Jan 09, 2017 12:57 pm

godlike wrote:For a first-person character controller the movement doesn't quite obey the laws of physics. The movement has to be snappy that's why there is no acceleration. The velocity is always constant.

Is that possible with the method you are describing?


Yes, you can control single bodies with forces almost as responsive as with velocity.
In the code snippet you see the math to calculate force and torque to result in given velocities.
I have not tested this a lot, no stairs in my scene, but it feels like playing Quake.
I assume it can climb on stairs and run over sloped terrain, but brobably would need some more work.

I think a smoothing system for the camera is necessary for both kinetic / dynamic approaches.
I expect this behaviour for stairs:
Julios kinetic controller: constant forward velocity but abrupt changes in height.
My dynamic one: No abrupt changes thanks to capsule shape, but non constant angle dependent velocity (could be fixed).

Code: Select all
   void AccumulateForce (float timestep, bool jump)
   {
      BodyData *data = (BodyData*) BodyGetUserData (playerBody);

      float mass, Ixx, Iyy, Izz; BodyGetMassMatrix (playerBody, mass, Ixx, Iyy, Izz);
      sMat4 matrix;      BodyGetMatrix(playerBody, matrix);
      sVec3 curLinvel;   BodyGetVelocity (playerBody, curLinvel);
      pos = matrix[3]; // assuming there's no offset
      BodyGetRotation (playerBody, orn);
      sVec3 curAngvel;   BodyGetAngVel (playerBody, curAngvel);

      sVec3 gd = upJoint->targetDir;
      sVec3 l = targetLinVel;
      l -= curLinvel; // subtract unwanted current velocity
      l -= gd.Dot (l) * gd; // no force at grav direction
      if (jump)
      {
         l += gd * 15.0;
      }

      sVec3 force = 0.3 * l * (mass / timestep);

      { // limit the force to some maximum value:
         float len = mass * 400.0;
         force /= len;
         sScalar mag = sqrt(force.Length()) - 1.0f;
         if (mag > 0.0) force /= 1.0f + mag*mag;
         force *= len;
      }

      sVec3 targetAngVel (0,0,0);
      sVec3 torque;
      {
         torque = targetAngVel / timestep;
         torque = matrix.Unrotate (torque);
         torque[0] *= Ixx;
         torque[1] *= Iyy;
         torque[2] *= Izz;
         torque = matrix.Rotate (torque);
      }

      data->force += force;
      data->torque += torque;

      BodyActivate (playerBody);
   }
User avatar
JoeJ
 
Posts: 1453
Joined: Tue Dec 21, 2010 6:18 pm

Re: Newton Character Controller

Postby Julio Jerez » Mon Jan 09, 2017 2:45 pm

not Joe tryin to do inverse dynamics on one rigid body, is in general a big mistake.
the problem is that you are seeing the body as single entity, by the is no who the engine sees it.

to make an example imagine a one dimensional system alone the x axis

if you have only one particle, the function you show to apply forces is always valid, not problem there
now imagine, the particle is in contact with another particle in front.

in this case the force you calculate will no apply the acceleration that you want, because the mass matrix of the system, is a function of all the connected bodies. now imagine you has n Bodies in a row, now the acceleration is divine by N. and this is when the stiff system come in, because usually the function is unaware of the configuration and in each frame try to achieve the desire velocity by
aping the same huge force given more and more energy the system.

the result is that at best you get a system when an object like a feather can push a one ton body. or at worse the accelerations are so huge that it gets into the real of numerical Presidion and solve errors.

It could be possible that know this we incorporate these ideas and make a multibody player, one the wake the configuration and solve the system, in order to calculate a better force. But the approached I took is a compromise, which is make the kinematic body has Mass, and let the engine solver do the calculation knowing that the body has a finite mass and as a result the bodies in contact canon get unlimited energy. This seem to work well, but it can be improve more.

@ Godlike, yes Linux will be broken with all the latest changes, do you have a windows version?
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Newton Character Controller

Postby JoeJ » Mon Jan 09, 2017 4:41 pm

Julio Jerez wrote:if you have only one particle, the function you show to apply forces is always valid, not problem there
now imagine, the particle is in contact with another particle in front.

in this case the force you calculate will no apply the acceleration that you want, because the mass matrix of the system, is a function of all the connected bodies. now imagine you has n Bodies in a row, now the acceleration is divine by N.


But this is what i want.
If i move against a light object, i push it and move slower.
If i move against a heavy object, the player max force can't overcome static friction, and i can't push it.
If i move into a cloud of monsters, they push me around, but is till have some control and can escape eventually.

Julio Jerez wrote:the result is that at best you get a system when an object like a feather can push a one ton body. or at worse the accelerations are so huge that it gets into the real of numerical Presidion and solve errors.


No, there is a max force in my code (hardcoded by mass * 400.0, I did not clamp torque, should be added as well).
By tweaking this it's possible to get some default behaviour probably good for an entire game.
But as always, keep max forces as small as possible.

However, don't wanna argue about this, also i did not use it for a real game.
There is also ongoing discussion about various player controller aproaches everywhere.
You would be the first to create one that makes everyone happy :)
User avatar
JoeJ
 
Posts: 1453
Joined: Tue Dec 21, 2010 6:18 pm

Re: Newton Character Controller

Postby Julio Jerez » Mon Jan 09, 2017 5:52 pm

JoeJ wrote:There is also ongoing discussion about various player controller approaches everywhere.
You would be the first to create one that makes everyone happy :)

I wish 8) , but that's a hopeless wish, I will be happy if I get one that is reliable and functional.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Newton Character Controller

Postby Leadwerks » Mon Jan 09, 2017 10:15 pm

I have modified some of the custom joint files to produce custom behavior. Do you want to try to implement these changes into Newton, or do you want me to provide my modified version of Newton?

I only use Hinge, Slider, and Ball joints, but the limits can be set dynamically or disabled on all of these, and sliders and hinges can be motorized:
http://www.leadwerks.com/werkspace/page ... e/_/joint/
User avatar
Leadwerks
 
Posts: 569
Joined: Fri Oct 27, 2006 2:54 pm

Re: Newton Character Controller

Postby Julio Jerez » Tue Jan 10, 2017 7:18 am

what does the joints has to do with the player code?
the joints in the custom library are for people to customize them to their specific behavior.
that's the idea in the first place and what I encourage people to do.
But that does not mean that particular user heuristics becomes part of the joints library.

only when a changes is novel enough or when a user show a real bug I added the change, otherwise the joints in the joint library are the starting point for sophisticated users to build on them or rewrite altogether.
It is what people like Joe, Wallabel, Dave gravel, You, and others has done over the years.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Next

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 29 guests

cron