I’ve discovered an issue in my character controller, and while I think that I may have a solution (I have yet to properly test it), I’m not enormously confident regarding game-physics, and so would like to check that what I’m doing isn’t a bad idea.
As I gather is standard for these things, my character controller doesn’t use dynamic physics; its velocity in particular is stored in a Panda “Vec3”, and its position is updated in my game-logic.
In order to then have my character controller respond to collisions with external objects (such as walls), I have a dynamic (not kinematic, I believe) rigid body attached to it, providing basic prevention of penetration. However, this alone doesn’t work, as the controller’s velocity remains unaffected. To remedy this, on each game-update I add the linear velocity of the dynamic body to my controller’s velocity, then zero the dynamic body’s velocity; this results in the dynamic body effectively producing a “reaction velocity” in response to collisions.
All of this seems to work fairly well–on my development machine, which is a little slow and in running my game seldom reaches sixty frames per second.
When I run the game on a faster test-machine, walls offer a little resistance, but I can nevertheless walk through them.
I think that I’ve traced this to my call to “doPhysics”, which I had been giving a maximum of one sub-step, and a sub-step size of 1/60.0–I think that I got these parameters from the forum, in a post responding to an issue in Panda 1.9’s handling of the default parameters. From my subsequent reading, I gather that this means that on a computer running at significantly faster than sixty frames per second the physics will not be updated every frame, and thus some logical movement-updates will happen without corresponding physics checks, and hence result in the ability to walk through walls.
My solution, then–the bit that I’m most unsure about–is to simply give “doPhysics” a maximum of “zero” sub-steps–which I gather instructs it to use the whole delta-time in a single updated, regardless of that delta-time–and to pass the delta-time as its sub-step size. (Come to that, does a specified sub-step size have any effect when “zero” sub-steps are indicated?)
This, I hope, produces variable physics steps, and a physics step on each game-update. My game isn’t intended to have physics puzzles, with the physics engine primarily providing penetration-prevention, the detection of objects and environment, and other such functions. As a result, I’m not terribly bothered about the loss of determinism–as long as the physics remain stable.
So, is my approach reasonable? Are there any issues that I should be aware of?