Constant acceleration in direction and facing point

Kim2

24-11-2008 00:46:10

Hi, a couple of basic questions.

I want to set an acceleration value (say, 5m/s/s) and then have an object accelerate in a direction at that value.


ships[i]->forceToApply = ships[i]->mass * accelVector;


The accelVector is direction with magnitude = acceleration amount (which I set to 5).

However, watching the linear velocity returned from the actor, this doesn't seem to provide the right amount of acceleration at all. Acceleration seems more like 20ms/s.

What am I missing here?


Second problem, I'm trying to orient the ship to face a point using torque.

When I was using Newton SDK I could get the ship to turn and face a point (only considering single axis of rotation) like this:


Quaternion r; Vector3 p;
p = ships[i]->mPosition;
r = ships[i]->mOrientation;

Vector3 directionToTarget = ships[i]->navPoints[0] - ships[i]->mPosition;
directionToTarget.normalise();
Vector3 negZ = r.zAxis() * -1.0;

Quaternion rotationNeeded = negZ.getRotationTo(directionToTarget);

float rotYaw = rotationNeeded.getYaw().valueDegrees() * -1.0;
float rotPitch = rotationNeeded.getPitch().valueDegrees() * -1.0;

//OverlayElement* guiCurr = OverlayManager::getSingleton().getOverlayElement("Core/CurrFps");
//guiCurr->setCaption(StringConverter::toString(rotationNeeded.getYaw() * -1.0));


ships[i]->torque = Vector3(0,0,0);

if(rotYaw < 0) {

// left
ships[i]->torque = Vector3(0, 20, 0);
}
else if(rotYaw > 0) {

// right
ships[i]->torque = Vector3(0, -20, 0);
}



With a bit more code to smooth out the turning so it doesn't wobble back and forth.

Using NxOgre the rotation is only going in one direction and it seems to go off axis until the ship is facing downwards and rotating around its local z axis.

What is the best way to get my ship facing a point using physics?

Thanks a lot.

mcaden

24-11-2008 04:59:38

1) Have you taken into account LinearDamping?

2) Try setAngularVelocity(...) instead of torque

mcaden

24-11-2008 07:02:13

Hope this helps, but my Enemy AI is currently using this. I'm not sure if it's the most accurate or best way to do it so if anybody else has suggestions/corrections please let me know.


Ogre::Vector3 facing = this->getGlobalOrientationAsOgreQuaternion() * Ogre::Vector3::UNIT_X;
Ogre::Vector3 dir = mHome - this->getGlobalPositionAsOgreVector3();
dir.y = 0;
facing.normalise();
dir.normalise();
Real angle = facing.dotProduct( dir );

setAngularVelocity( Vector3( 0, angle * 100, 0 ) );
forward();


Just replace mHome with whatever your target position is as a Vector3. Right now this is a part of my AI where the enemy goes too far from his tether in a normal wander state so it steers back towards home. I don't really deal with acceleration. I have made sure to use this->setMaxAngularVelocity( 15 ); in my constructor. This can be tweaked to your liking along with AngularDamping to have the desired effect.

EDIT: This ignores the Y axis. It is straight left/right rotation.

Kim2

24-11-2008 10:34:03

Unfortunately I can't set velocity directly because eventually I need to take into account an array of thrusters with position and orientation. Under Newton I had a system set up simulating thrusters with local forces but performance broke down and it was a nightmare trying to coordinate which thruster should be firing for particular movement. So I am trying a different approach. I'll get the needed end result force for movement/rotation and then check if that force is possible with the array of thrusters that exists for that ship (applying the end result force/torque rather than many small local forces).

Kim2

24-11-2008 10:59:05

What does linear damping do?

mcaden

24-11-2008 13:24:16

For an exact definition Betajaen would probably have to post.

My understanding is technically wrong but BASICALLY it's a resistance to force or additional inherent friction...something along those lines.

Kim2

24-11-2008 19:37:08

I'll see what betajaen says then.

betajaen

24-11-2008 19:51:36

My understanding is technically wrong but BASICALLY it's a resistance to force or additional inherent friction...something along those lines.

I understand it to be the resistance to acceleration of an object. The higher linear damping; the harder it is to push something.

Prophet

24-11-2008 20:14:28

I've always thought it was how fast it slowed down. Like air-resistance. >.<

reptor

24-11-2008 22:33:40

Is there an example in the shock absorbers of a car? They are sort of "dampers". They resist fast movement, but allow slow movement pretty well. In some shock absorbers it is done so that there is a small hole and liquid (oil) is forced through it when the shock absorber either extends or compresses (depending on the up/down movement of the wheel). If the movement is slow then the liquid has not much problems going through the hole, and the movement is not slowed much, but if the movement is fast then the liquid has trouble going through the hole and causes a lot of resistance.

So, if there is a "shock", the absorber is more effective in slowing it down, but if the movement is very slow then it isn't relatively slowing it down much.

The viscosity of the liquid is of course an important factor.

I don't know, I just decided to throw this example here if it is related. I don't know :)

Kim2

24-11-2008 23:39:42

Well that's interesting to be sure, but ahhh... no help on the acceleration/turning?

Well at least, first thing, why do the objects end up facing straight down when I apply a torque that should be rotating it purely around the y axis?

xadh00m

25-11-2008 09:03:44

Maybe this would be a possible solution:
An extra parameter has been added for joints to enable acceleration based springs. Acceleration based springs do not take the mass of the attached objects into account. See NxJointDesc::useAccelerationSpring in the documentation for details.
http://developer.nvidia.com/object/phys ... notes.html

I could not check this, but would be pleased if someone would share his/hers
experience.

Kim2

25-11-2008 19:57:08

I am wondering if maybe I need to change some rigid body parameters for it to work properly... I am only setting mass and inertia vector at the moment. Could the COM be wrong or something to cause the off axis rotation?

Kim2

25-11-2008 20:03:43

Setting the angular velocity manually gives the expected result but adding torque starts it tilting. I guess physx is taking into account things that newton sdk didn't... or automatically setting the COM from the volume?

I will have to ask on the physx developer forum I suppose if nobody here knows.