Control X-, Z-axes manually. Possible?

DanielH

05-05-2008 23:30:46

Hello!

I'm not sure if I approach this in the right way so I'll first explain what I'm trying to do.

I'm making a game that could said to RTS like but only with battle tanks. It's click-and-move based and I perform pathfinding calculations when the player clicks on the ground. What I end up with is a spline with the path to travel from the current position to the position the player wanted to move to.

To make the game a little cooler, I want to add better physics to the tanks than just "glue" them to the terrain. I want to add suspensions to the tank treads and also be able to make them "jump" a little when nukes hit the ground in the surrounding area.

The problem is how to integrate this physics. Since I already got a path with positions and a rotation angle in the xz-plane for each point on the path, I need to add some constraints to the movement of the actor.

I've been reading the API reference and I've understood I can freeze movement in specific axes using NX_BF_FROZEN_POS_* flag. That might be good when the tank is just traveling along the spline, but that wouldn't be too good if I want to be able to "jump" when missiles hits the ground near of it. So apparently that is not a good idea.

I also don't know how to move the actor in x,z direction while letting PhysX take care of the y-axis and orientation. As far as I've understood, moveGlobalPosition can only be used when NX_BF_KINEMATIC is set (which is not what I want to do). Looking at setGlobalPosition's docummentation makes me kind of doubt it will be useful either.

I've read somewhere that the best way to manually move actors is to add impulses. I then have two questions. A. Does the impulses have any effect if the X and Z axes are frozen? (Perhaps they won't be needed to be froozen if the impulses correct the position every frame?) B. How to I calculate correct impulses to make tank following the spline and also take the terrain slope into account.

As you notice I really don't have a clue how to solve this. I'm not even sure it's a wise idea to use PhysX for this. Any guidance would be helpful.

betajaen

05-05-2008 23:50:13

1. NX_BF_FROZEN does what it says on the tin. I expect it's intended usage was for 2D physics. But your situation is just as good. So yeah.

2. Have a look at the source of the Actor::moveTo function I wrote. You can use that as a basis for your own.