Vehicle: jitter between mBody->mNode and children...

Estrich

22-05-2006 21:47:52

Heya,

We are currently working on a racing game using the nxOgre wrapper (thanks for the great work!) more precisly the prefab vehicle system provided with the wrapper.
To attach a 3rd person camera to the car we created a couple of scenenodes which we attached to the mBody->mNode inside the vehicle (via createChildSceneNode()).
The problem is, that now the car is jittering relative to the camera scene node.
When outputting the position of the mBody->mNode and the position of the childnode where the camera is attached to (via _getDerivedPosition()) the distance between these two nodes is varying causing the jitter.

Usually there shouldn't be a variation in the distance between a node and his child so am I missing something or how can i solve this problem?

thanks,
estrich

betajaen

23-05-2006 09:08:32

I've noticed this too, but not so it's very noticeable

I'm sure the jitter is the car shape itself pressing against the ground then being forced back up, hence a small jitter.

What I'd do, is just generate an average Vector3 over a short time of the car position so it smoothes out the camera movement.

Estrich

25-05-2006 00:28:24

hmm... I've experimented a little more and I think it's not a problem with the shape beeing pressed against the ground and back up as the jitter is also clearly visible in midair.
We're already smoothing the camera movement but it's not enough as the jitter is still visible.

Any other idea what could be the problem and how to solve it?

betajaen

25-05-2006 08:22:37

How much is it of a Jitter? Is it completely totally mad, or just annoying to look at?

If you can get NxTutorialx05 (I think) the vehicle demo does the vehicle in there jitter as much as yours does?

magura

01-06-2006 06:07:33

I had this issue too, where the vehicle would be pressing really hard against the ground, causing it to "glitch around"

All of my scales were set to a different scale to what is commonly found in the vehicle prefab i think, so that a large (few thousand) force downwards was throwing everything out.


mBody->addForce(Ogre::Vector3(0,-75000,0));


just remove that and it is fine (on the scale i have everything based around anyway).

EDIT: that code is from nxprefab_vehicle.cpp

betajaen

01-06-2006 09:40:29

And the reason why that is in, is to stop the car flipping over when you turn - like an anti-roll bar, except it doesn't power slide around the corner.

magura

02-06-2006 07:57:54

hmmm true, i do have that issue - at speed anyway. I have got speed limitation working (which is important for the sim im developing).

Its possible to change the centre of gravity on the nxogre prefab, but im not sure if its being passed onto novodex? Centre of gravity was in the 2.0 preview vehicle class and it seemed to resolve that bodyroll issue.


anyway - speed limiting

void vehicle::accelerate(float _strength)
{
if(mSpeedLimiter)
mMotorForce = (getDriveVelocity() < mMaxVelocity)?_strength:0;
else
mMotorForce = _strength;
}


and the other functions -

float vehicle::getDriveVelocity()
{
computeVelocity();
return NxMath::abs(mLocalVelocity.z*3.6); // Why *3.6? Dont know but it makes it work in the nx demos
}


and

void vehicle::computeVelocity() {

getMostTouchedActor();

NxVec3 relativeVelocity;
if (mMostTouchedActor == NULL || !mMostTouchedActor->isDynamic()) {
relativeVelocity = mBody->mActor->getLinearVelocity();
}
else {

relativeVelocity = mBody->mActor->getLinearVelocity() - mMostTouchedActor->getLinearVelocity();
}

NxQuat rotation = mBody->mActor->getGlobalOrientationQuat();

rotation.inverseRotate(relativeVelocity);
mLocalVelocity = relativeVelocity;
}


That speed limiter works only when applying extra throttle, so going downhill without throttle, for example, will still accelerate


I'm going to try and get the centre of gravity passing through to novodex now by trawling through the raycastcar demo

Edit: got centre of mass going - it just needs to set the actor's CofMass during construction. Sorry for offtopic'dness :oops:

betajaen

02-06-2006 09:32:04

If your using the CVS version, the center mass is defined when you create the blueprint, as so:-

NxTutorialx06.cpp(50)

mBlueprint->mCenterOfMass.set(0,-1.5,0);


If your using Preview 3, then I think it's the line in nxPrefab_vehicle.cpp that is like this:-

mBody->mActor->setCMassOffsetLocalPosition(...);


p.s. Thanks for the speed limiter, I'll add it into 0.5 if you want. :D

magura

05-06-2006 09:59:35

heh yeh thatd be good if you did. However, I'm still having issues negotiating my way around the way the prefab vehicle is laid out, with the blueprints and the gearbox/motor/wheel blueprints etc.

I know most of it comes pretty much verbatim from the novodex sample, but any chance I could get you to give a crashcourse in the vehicle class - im just not sure im changing things in the 'right' way ... ie i want to adhere with the rest of the library, but im changing a fair few function signatures in the process of modifying the class

betajaen

05-06-2006 10:17:49

Do what you have to, once your finished, I'll have a little look, and if it's better than mine (which it probably is), I'll add it into the source if you like.

Don't worry about it changing it too much, unless you've embedded python or it's no longer written in C++ anymore :P

Estrich

07-06-2006 00:23:59

How much is it of a Jitter? Is it completely totally mad, or just annoying to look at?

If you can get NxTutorialx05 (I think) the vehicle demo does the vehicle in there jitter as much as yours does?


Heya and sorry for me not replying for so long, haven't had much time to work on the project in the last weeks.
Anyway, we solved our jitter problem but as I'm not aware of what really went wrong I can't tell you exactly what my colleague did to solve it.
I'll ask him if he would like to write a reply with the details of the fix.

Anyway, thanks for the great help!
Estrich

gzmzhen

18-08-2006 22:39:35

Although I'm using Newton for the physics, I seem to have a similar problem to this, can you ask your friend to briefly explain what he did to solve it? It'll give me a good direction to look.

Thanks,
Nate

[EDIT] I actually found out that it's because newton is updating on a different time scale than my camera. I moved the netwon frame listener code into one of my own to fix this problem. [\EDIT]

betajaen

18-08-2006 23:41:17

It's been a while since he's posted and I doubt he'll see your post, but I have an idea.

Get the coordinates of your car, vehicle or whatever.

Move the camera scenenode to the X,Z position of the car and ray cast the floor position as Y. Then from there create add an offset(say back a bit and higher up) multiply it by the car's quaternion direction, and lookAt the car.

That way the camera should be fairly stable.

gzmzhen

19-08-2006 19:00:05

Actually my problem had nothing to do with the camera moving too slowly or anything like that, but the way that Newton is set up you can only update in intervals that are greater than 1/600th per second but less than 1/60th per second. So, the frame listener basically updates everytime enough time passes (so in my case when I had 22fps in debug mode it updates several times - about three - at once).

So, since my camera updates every frame, the car would move "on a different schedule" so you could see that the car and the camera weren't in sync.

I fixed this by simply getting rid of the newton frame listener and updating the world at the same time I update my camera position. (Effictively squashing two framelisteners into one.)

The camera works fine now! Thanks for your advice anyways!

Toby

22-08-2006 21:32:06

Can I do same with NxOgre? because I have similar pb.
But I think not.

betajaen

22-08-2006 22:36:02

The jitter is only up and down if I can remember correctly, so my way should work.

Toby

23-08-2006 13:06:45

Maybe I do not understand well your solution.

I have two framelistener, one in world, and one in my launcher class which create camera.
I also create an extendedCamera class which attached camera and have two node (target and position), I setAutoTracking true on TargetNode and setYawFixed true.
I attached also two nodes in my car class.(sight node and camNode)
Then framelistener of world update carNode, sightNode and camNode position and render it. But my framelistener update camera position after. Then movable object jitter.

Or if you know how to attached camera to car node and camera do not flip, roll...

thx.

betajaen

23-08-2006 17:38:55

Okay this is my idea as a Pseudo code.


scenenode cameranode
cameranode.attach camera

in every frame:
pos = car.pos
y = raycast down from pos
pos = (car.pos * car.direction) + Vector3(0,2,-4)
pos.y = y;
camera.pos = pos
camera.lookat = car
end:



Basically it puts the camera behind the car what ever angle the car is facing, it climates the vertical jitter by basing the y value on the ground underneath.

As the camera node is separate from it will not flip over or do any weird camera movements if the car does.

Toby

10-01-2007 12:13:13

I put up thi topics because I have always this pb. I read in Ogre forum that you treat this problem Betajean.
I remember problem: Car body jitter (tremor) and not camera, not track in my car game.
vidéo to see it:
http://artcardeus.free.fr/media/Movie/tremor2.avi

Then I verify my loop. And I try to reorder setup like in tutorial.

1/ setup config
2/ setup render system
3/ setup resources
4/ start world (new world(mRoot, true))
5/ setup input manager
6/ setup sceneManager
7/ Setup camera..
8/ create world scene
9/ create my body...
10/ add framelistener
11/ startRendering

Thanks for your help.

You must know that all this action is not in same class, nor in same function. If it is important I will post a diagram.

Edit: Jitter is same as ball in Ogre3D forum, jitter appears in movement direction.

betajaen

10-01-2007 13:24:59

Well, I must admit your game is getting better. (I've been following it secretly, now and again. I get hits from your website as a referrer).

But have you tried updating the camera position inside a NxOgre iterationListener? I wrote it a while back for these situations.

There isn't a tutorial for it but:



class cameraWatcher : iterationListener {
void before(Ogre::Real delta) {}

void after(Ogre::Real delta) {
mCamera->setPosition(myCar->getGlobalPosition());
mCamera->lookAt(myCar->getGlobalPosition());
}

};

...

mWorld->addListener(new cameraWatcher());



That should move the camera in the same frameListener that NxOgre uses, just after the car has moved.

However since your using an older version of NxOgre, and I can't remember when I put this in you may have to transplant a bit of the new NxOgre over. (iteration_listener.h, the world addListener function and vector, and modify the world simulate to fire the listeners.)

Toby

10-01-2007 14:22:59

Hi, I am happy to know you follow my developement. I will try to update my website more often than now. When I will finish this game I render source free and open.

I just tried to derive my followCamera to iterationListener but my bug stay.(but your class work well)

In a topic on Ogre3 forum you say that this bug appears if we do not setup main framelistener and world::framelistener in good order.

In main() I create a gameManager that setup step 1 to 5 in my previous post. Then I change gameState(whiches are static class like in ogre tuto) to playState. This setup step 6 to 9. And finaly step 10 11 launch by main().

betajaen

10-01-2007 14:34:06

Just a shot in the dark here, but have you actually dumped a log of the cars position to a file? Perhaps for some weird reason the car is jumping around itself.

Toby

10-01-2007 18:25:01

This is an extract of NxActor and SceneNode position at each frame:


NxActor position: X: 260.111 Y: 23.5713 Z: 1.87432
SceneNode position: X: 260.111 Y: 23.5713 Z: 1.87432
NxActor position: X: 260.586 Y: 23.573 Z: 1.88504
SceneNode position: X: 260.586 Y: 23.573 Z: 1.88504
NxActor position: X: 260.586 Y: 23.573 Z: 1.88504
SceneNode position: X: 260.586 Y: 23.573 Z: 1.88504
NxActor position: X: 261.061 Y: 23.5748 Z: 1.89589
SceneNode position: X: 261.061 Y: 23.5748 Z: 1.89589


Killed by Betajaen, for the sanity of the forum

betajaen

10-01-2007 19:04:34

Right, I had a look before cutting most of it out.

I can't really tell, but what are you doing with the car. Driving forward, or racing around the track?

Either way, I can't really tell.

Toby

10-01-2007 21:50:02

This part of position of my car had logged in drivind forward in dir X. As we can see X position grow up constantly. I do not take importance of Y and Z position because track is not plane and when I accelerate my car turn a little due to a bad construct of shape.

If you have time to spend to look into my code I can release it.

This bug seems to me incomprehensible. But I will make a diagram class to explain well how I construct my application.

Toby

11-01-2007 07:03:21

I test again coords of my car. Then I start with car in air and let it fall. Then it appears that Y coord not update at each frame. Is it normal??
I have two or three times same coords Y. How to foce physX update at each frame?

edit: Is it a frame rate problems? When I took this coords my application rate at 30 fps.

Toby

15-01-2007 13:13:29

Then, a news in this topics. I log Actor position and mesh attach to it, a simple cube. My Actor does not move. Just a gravity is set. Look log

NxActor position: X: 0.0170059 Y: 40.7673 Z: -0.0486111
SceneNode position: X: 0.0170059 Y: 40.7673 Z: -0.0486111

NxActor position: X: 0.0171731 Y: 40.7681 Z: -0.0488244
SceneNode position: X: 0.0171731 Y: 40.7681 Z: -0.0488244

NxActor position: X: 0.0173398 Y: 40.7689 Z: -0.0490327
SceneNode position: X: 0.0173398 Y: 40.7689 Z: -0.0490327

NxActor position: X: 0.0175062 Y: 40.7696 Z: -0.049234
SceneNode position: X: 0.0175062 Y: 40.7696 Z: -0.049234

NxActor position: X: 0.0176723 Y: 40.7703 Z: -0.049431
SceneNode position: X: 0.0176723 Y: 40.7703 Z: -0.049431

But while I do not apply no force no jitter appear. But if I apply a little force after even if actor does not move, jitter appear. Why?
Must I do a average Vector3 like Betajean says in previous post?

betajaen

15-01-2007 15:15:19

It seems, how I understand it is since the car mesh is not sleeping (it has to be constantly awake for it to work), it's quickly falling through the mesh and popping back up again, hence the jitter. Normal bodies this wouldn't be much of a problem, and they auto-sleep after a few seconds anyway, but the car isn't a normal body.

I believe by getting an average of the camera movement over several frames would do the trick.

Toby

15-01-2007 18:31:27

Yes you are allright. Indeed position change because my car slipping(x increase) and suspensions are wake up.
Then to reduce the jitter (its famous jitter) I synchronized my framelistener to nxOgre by do not autostart world. And at each frame I call world::frameStarted() . And I update camera only if body car world position change between 2 frames. Moreover if fps is too quick I keep out input update and camera update.

With this trick jitter reduce but I will smooth again camera system.

I have also a cycling bug. Actually timeSinceLastFrame is to 0.016 (ie 60 fps) Regularly timeSinceLastFrame grow up for one frame to 0.40 and fall to 0.005 just after. Maybe this come from my graphic card. This causing a clipping.
Thanks again for your help.

betajaen

15-01-2007 19:55:33

Do you have VSync turned on? That'll make timeSinceLastframe all the same.

Toby

20-01-2007 23:18:21

Hi, I find how to smooth camera movement. I see in stuntplaygroud source code how he update camera position. then I correct my code and add in nxOgre a function frameStarted(float time).
I do not start automatically world and I call this last function in order to set frame rate always at 60fps. I call it many times or not or just one. As you can see by testing my new release V0.4 on artcardeus web site movement are smooth.

Thanks for your help, I consider it is solved.

NickM

21-01-2007 12:59:45

Hi, I find how to smooth camera movement. I see in stuntplaygroud source code how he update camera position. then I correct my code and add in nxOgre a function frameStarted(float time).
I do not start automatically world and I call this last function in order to set frame rate always at 60fps. I call it many times or not or just one. As you can see by testing my new release V0.4 on artcardeus web site movement are smooth.

Thanks for your help, I consider it is solved.


I just tried V0.4, it's all looking very good so far, the chase camera is great, keep up the good work.

Toby

24-01-2007 09:04:33

Thanks, I will code weapon system now. But I want also improve car behaviour like a rally game. If you know how to set properly NxTireFunctionDesc, tell me :)

NickM

24-01-2007 15:20:09

Thanks, I will code weapon system now. But I want also improve car behaviour like a rally game. If you know how to set properly NxTireFunctionDesc, tell me :)

I'm working on it but I've stopped at the moment to do my own proper chase camera so I can get a better feel for how the car is handling, if I make any progress on the tyre physics I'll let you know.