Many character controllers?

Trioxin
Posts: 7
Joined: Mon Aug 15, 2011 4:58 am

Many character controllers?

Post by Trioxin »

Simple question with most likely a not so simple answer.

I want a scene (Real time strategy) with large numbers of characters on the scene at any given time (20,40,60 etc). I've seen a lot of people complaining however that the character controller is inefficient for any more than a few characters, estimating between 0.8 and 3ms for each active controller, which in a best case limits me to 20 at a time maximum.
Is there a more efficient way of representing character movement? Really the only aspect I'm interested in is the ability to move up ramps/stairs and the possibility of including jump functionality.

Any suggestions would be much appreciated!
Trioxin
Posts: 7
Joined: Mon Aug 15, 2011 4:58 am

Re: Many character controllers?

Post by Trioxin »

Nobody? :(
Norbo
Posts: 5
Joined: Tue Nov 06, 2007 8:52 am

Re: Many character controllers?

Post by Norbo »

I'm not intimately familiar with Bullet, but I can give you some general advice.

If you can guarantee via your content that characters won't get into situations where you have to verify step-ups for validity (to avoid stepping up into a ceiling), then you can get by with a much simpler approach.

One possible option is to just make a rigid body that is supported by a ray cast. In other words, cast a ray from the bottom of a capsule to the environment. Use the hit location and supporting object to compute relative velocity, and use the hit T parameter to position the character at the correct vertical location offset from the ground.

By making that ray long enough and having the vertical position correction, you get automatic (unsafe) upstepping. By extending the ray further down to 2 * MaximumStepHeight, you can also support automatic down stepping.

This is pretty simple to implement and will be a lot faster than a full-featured character controller.
Trioxin
Posts: 7
Joined: Mon Aug 15, 2011 4:58 am

Re: Many character controllers?

Post by Trioxin »

Thanks for the reply :)

Could this not provide some potentially unpleasant behaviour, such as walking up an undesirably steep angle, or refusing to slide back down from one?

I've started having a look at this approach and have encountered a couple of caveats:
Since the object is essentially being translated every time it gets too low, it's resulting in the gravitational pull getting stronger.
It's also resulting in a substantial amount of jitter.
Norbo
Posts: 5
Joined: Tue Nov 06, 2007 8:52 am

Re: Many character controllers?

Post by Norbo »

Could this not provide some potentially unpleasant behaviour, such as walking up an undesirably steep angle, or refusing to slide back down from one?
If not addressed, yes. But dealing with it is easy; the ray cast should return a normal. You can compute the slope angle based on the surface normal. If the slope is too steep, consider the character to not have traction.
Since the object is essentially being translated every time it gets too low, it's resulting in the gravitational pull getting stronger.
You should correct the velocity of the character along the surface normal in addition to the position.
It's also resulting in a substantial amount of jitter.
The ray should target a position such that the raycast is still hitting the ground, but barely- give it a margin. You don't want it flipping between "supported" and "unsupported" due to numerical problems each frame.

I have a somewhat old C# implementation of this sort of character if you'd like to take a look to see how it works: http://bepuphysics.codeplex.com/SourceC ... troller.cs

There's also a more advanced CharacterController in that project, but it's a lot more complicated and would probably be a pain to learn from/port over (and it's slower than the SimpleCharacterController by virtue of its extra features).