Simple vehicle implementation
Re: Simple vehicle implementation
U're amazing, thanks! But to be honest, I had no idea I would have had so many questions about your vehicle physics implementation. But how can I change center of mass? It seems that it flips over every time I take a turn and I believe that the mass center might be the reason. Also, is there any way to change width of wheels and acceleration or power of the car?
Re: Simple vehicle implementation
The entity.CollisionInformation.LocalPosition offsets the shape from the entity.Position. This is effectively the same thing as changing the center of mass. So, if you want the center of mass to be lower relative to the shape, the LocalPosition should push the shape higher. The default demos vehicle configuration uses (0, .5f, 0).But how can I change center of mass?
The wheels are actually ray casts, so no. You could increase the width of the graphical representation though. If greater traction is your goal, then increasing sliding friction would help (in the constructor of the WheelSlidingFriction given to the Wheel).Also, is there any way to change width of wheels
Acceleration is defined by the WheelDrivingMotor configuration. Each wheel's WheelDrivingMotor has a grip friction, maximum forward force, and a maximum backward force. Increasing the force and grip friction will make the car accelerate faster.and acceleration or power of the car?
Re: Simple vehicle implementation
And what if I would like to reset position on the car? I mean setting position of it is quite obvious, but i would like it to position it horizontally (for example put it on the wheels after it's been flipped). And I've noticed that when driving high speed, the vehicle tends to slide, wondering why?
Re: Simple vehicle implementation
Set the orientation to some known good state. Quaternion.Identity might work. However, setting the Orientation property counts as a nonphysical teleportation. It can get your vehicle into invalid states. If this is a concern, you could pull it back to a good orientation by applying angular impulses or by verifying the state before applying it. Setting the Orientation is easy, thoughAnd what if I would like to reset position on the car? I mean setting position of it is quite obvious, but i would like it to position it horizontally (for example put it on the wheels after it's been flipped).

If you mean it slides when turning at high speeds, that's just insufficient sliding friction. However, sliding at high speeds is a common real-world phenomenon.And I've noticed that when driving high speed, the vehicle tends to slide, wondering why?
Re: Simple vehicle implementation
Yepp, everything works fine now. Maybe you remember when I asked about models connected with vehicle? Right now I'm facing this problem, cause I put it off till today. Well, it's just now I have loaded model, working car, the last thing is to glue these two together. I have this code:
But code above doesn't seem to change rotation in all directions (Y is the same you showed me with atan for x and z and works ok), but there is problem with X and Z - the model seems to be too horizontal, it doesn't fit the hill angles. I suppose it may have something to do with Body.Orientation.W, but no idea how to match all these values...
[EDIT] Oh, and I totally forgot - my custom model class has rotation field, which is Vector3 - it gets x,y and z parameters in radians.
Code: Select all
arModel.Position = vehicle.Vehicle.Body.Position;
carModel.Rotation = new Vector3 (vehicle.Vehicle.Body.Orientation.X, angle, vehicle.Vehicle.Body.Orientation.Z);
vehicle.Update(space.TimeStepSettings.TimeStepDuration, KeyboardState);
}
[EDIT] Oh, and I totally forgot - my custom model class has rotation field, which is Vector3 - it gets x,y and z parameters in radians.
Re: Simple vehicle implementation
That is likely what is known as Euler angles. They are indeed a very common representation (slipped my mind before[EDIT] Oh, and I totally forgot - my custom model class has rotation field, which is Vector3 - it gets x,y and z parameters in radians.

The Orientation property is a quaternion; the individual values do not represent angles by themselves.carModel.Rotation = new Vector3 (vehicle.Vehicle.Body.Orientation.X, angle, vehicle.Vehicle.Body.Orientation.Z);
I would very strongly recommend running away from Euler angles as fast as you possibly can. The entity.WorldTransform tells you exactly where the entity is in a graphics-convenient format. Transforming the model by the WorldTransform will make the model follow the entity. The idea of matrices and transformations may appear daunting at first, but if treated like a set of tools in a tool box instead of a bunch of numbers, they are really quite simple- far, far simpler than Euler angles.
The GettingStartedDemo shows this in use. Also, for graphics stuff, check out the XNA website samples for ways of managing transformations.
Re: Simple vehicle implementation
Yes, I've already learnt that using matrices is some (in my case not huge so far) simplification. But I'm afraid I am forced to use 'regular' (Euler) due to my class requirements (yeah...) and the fact, that I would be forced to completely change some code which I'd really love to avoid
That's why I was wondering if I can 'extract' the exact angles from a quaternion.

That's why I was wondering if I can 'extract' the exact angles from a quaternion.
Re: Simple vehicle implementation
Oof; well, then I would recommend doing as much of the math as possible in non-Euler angles before doing a final conversion.But I'm afraid I am forced to use 'regular' (Euler) due to my class requirements (yeah...)
It is indeed possible. The specifics vary on exactly what convention of Euler angles are being used (another one of those hidden unintuitive factors). Unfortunately, there's no helper methods in BEPUphysics for this, and I'm not aware of any Euler decomposition methods in XNA either (there are some Euler composition methods, like Quaternion.CreateFromYawPitchRoll, but those are conceptually simple).That's why I was wondering if I can 'extract' the exact angles from a quaternion.
I'd recommend googling it- http://www.euclideanspace.com has some pages about this too.
Re: Simple vehicle implementation
Ok, I found a solution with very simple explanation. If someone had the same problem, here's a link: http://forums.create.msdn.com/forums/p/4574/23763.aspx
Thank you Norbo for the all effort you put into solving my problems, I'm very glad I came here for help!
Thank you Norbo for the all effort you put into solving my problems, I'm very glad I came here for help!

Re: Simple vehicle implementation
@Update: Do you think is it possible to leave just wheels visible in vehicle body? 

Re: Simple vehicle implementation
The answer is yes, though I don't exactly know what you mean
The physics are totally separate from, and impose absolutely no requirements on, the graphics used to represent the physics. You are free to do whatever you want.

Re: Simple vehicle implementation
Yeah, but I mean is hide these blocks and show only wheels for example in a demo program (cause I have quite similar, not to say almost exactly the same) 

Re: Simple vehicle implementation
If you just don't want the vehicle body entity to be visualized by the ModelDrawer, then do not add the body entity to the ModelDrawer. The wheels are handled separately and will still be visible.