[SOLVED] PhysX vehicle wheel issues

A place for Ogre users to discuss non-Ogre subjects with friends from the community.
Post Reply
User avatar
CoreDumped
Gremlin
Posts: 177
Joined: Sun Aug 05, 2007 3:55 pm
x 14

[SOLVED] PhysX vehicle wheel issues

Post by CoreDumped »

As my vehicle gains speed, the wheels gradually move backward from their original position, as if they are being pulled back from their suspension

screenshots while car is at running at high speed and while its at rest
http://www.flickr.com/photos/23370020@N03/3258280735/
http://www.flickr.com/photos/23370020@N03/3258285897/

Any idea why this is happening and how I can fix it?

Thanks.

P.S.: Ignore the values on the UI in the screenshots. Here is the actual configuration of the vehicle:

Code: Select all

	-- prepare a vehicle
	vehicleConfig = VehicleConfiguration(getRandomName("Vehicle"))
	vehicleConfig.density = 700
	vehicleConfig.centerOfMass = Vector3(0, -0.5, 0)
	pos = Vector3(0, 15, 0)
	vehicleConfig.initialPosition = pos
	log("Position is:" .. pos.x .. "," .. pos.y .. "," .. pos.z);

	-- create the chasis
	chasisConfig = ChasisConfiguration("audi_chasis.mesh")
	chasisConfig.localPose = Vector3(0, 1.0, 0)
	vehicleConfig:setChasisConfiguration(chasisConfig)

	-- prepare the wheels
	wheelSuspension = 0.4
	wheelRadius = 0.5
	wheelWidth = 0.6
	maxBrakeForce = 1000
	springRestitution = 80000
	springDamping = 10000
	springBias = 0
	frontWheelHeight = 0.1
	rearWheelHeight = 0.1
	frontWheelDistance = 2.00
	rearWheelDistance = -2.15
	leftSide = 1.20
	rightSide = -1.20


	-- Wheel 1 (Front Left)
	wheelConfig = WheelConfiguration("1", "audi_wheell.mesh")
	wheelConfig.localPose = Vector3(leftSide, frontWheelHeight, frontWheelDistance)
	wheelConfig.steerable = true
	wheelConfig.affectedByHandbreak = true
	wheelConfig.wheelSuspension = wheelSuspension
	wheelConfig.springRestitution = springRestitution
	wheelConfig.springDamping = springDamping
	wheelConfig.springBias = springBias
	wheelConfig.wheelRadius = wheelRadius
	wheelConfig.wheelWidth = wheelWidth
	wheelConfig.maxBrakeForce = maxBrakeForce
	vehicleConfig:addWheelConfiguration(wheelConfig)

	-- Wheel 2 (Front Right)
	wheelConfig = WheelConfiguration("2", "audi_wheelr.mesh")
	wheelConfig.localPose = Vector3(rightSide, frontWheelHeight, frontWheelDistance)
	wheelConfig.steerable = true
	wheelConfig.affectedByHandbreak = true
	wheelConfig.wheelSuspension = wheelSuspension
	wheelConfig.springRestitution = springRestitution
	wheelConfig.springDamping = springDamping
	wheelConfig.springBias = springBias
	wheelConfig.wheelRadius = wheelRadius
	wheelConfig.wheelWidth = wheelWidth
	wheelConfig.maxBrakeForce = maxBrakeForce
	vehicleConfig:addWheelConfiguration(wheelConfig)

	-- Wheel 3 (Rear Left)
	wheelConfig = WheelConfiguration("3", "audi_wheell.mesh")
	wheelConfig.localPose = Vector3(leftSide, rearWheelHeight, rearWheelDistance)
	wheelConfig.accelerated = true
	wheelConfig.affectedByHandbreak = false
	wheelConfig.wheelSuspension = wheelSuspension
	wheelConfig.springRestitution = springRestitution
	wheelConfig.springDamping = springDamping
	wheelConfig.springBias = springBias
	wheelConfig.wheelRadius = wheelRadius
	wheelConfig.wheelWidth = wheelWidth
	wheelConfig.maxBrakeForce = maxBrakeForce
	vehicleConfig:addWheelConfiguration(wheelConfig)

	-- Wheel 4 (Rear Right)
	wheelConfig = WheelConfiguration("4", "audi_wheelr.mesh")
	wheelConfig.localPose = Vector3(rightSide, rearWheelHeight, rearWheelDistance)
	wheelConfig.accelerated = true
	wheelConfig.affectedByHandbreak = false
	wheelConfig.wheelSuspension = wheelSuspension
	wheelConfig.springRestitution = springRestitution
	wheelConfig.springDamping = springDamping
	wheelConfig.springBias = springBias
	wheelConfig.wheelRadius = wheelRadius
	wheelConfig.wheelWidth = wheelWidth
	wheelConfig.maxBrakeForce = maxBrakeForce
	vehicleConfig:addWheelConfiguration(wheelConfig)

	-- Create the vehicle
	vehicle = vehicleManager:createVehicle(vehicleConfig)
	return vehicle
Last edited by CoreDumped on Sat Feb 07, 2009 6:59 pm, edited 1 time in total.
User avatar
syedhs
Silver Sponsor
Silver Sponsor
Posts: 2703
Joined: Mon Aug 29, 2005 3:24 pm
Location: Kuala Lumpur, Malaysia
x 51

Re: PhysX vehicle wheel issues

Post by syedhs »

This is mostly due to SceneNode of the wheels being updated one frame behind the chassis.

To solve the problem, the easiest is to do the update for wheels and chassis in one member function probably something like this:-

Code: Select all

Vehicle::updateBodies(Real time)
{
 NxVec3 chassisPosition = mActor->getGlobalPosition();
 NxQuat chassisOrient = mActor->getGlobalOrientationQuat();
 // update your scene node here...

 // now update your wheels here too...
}
I have got similar problem, so I hope you can solve yours too. :)
A willow deeply scarred, somebody's broken heart
And a washed-out dream
They follow the pattern of the wind, ya' see
Cause they got no place to be
That's why I'm starting with me
User avatar
betajaen
OGRE Moderator
OGRE Moderator
Posts: 3447
Joined: Mon Jul 18, 2005 4:15 pm
Location: Wales, UK
x 58
Contact:

Re: PhysX vehicle wheel issues

Post by betajaen »

Luis and I (mostly Luis) solved it in NxOgre. We used a mixture of interpolation, and modifying the position of the wheel. The code is in the NxOgre SVN if anyone wants a peek at it.
User avatar
CoreDumped
Gremlin
Posts: 177
Joined: Sun Aug 05, 2007 3:55 pm
x 14

Re: PhysX vehicle wheel issues

Post by CoreDumped »

Thanks a lot guys. I'll try it out.
User avatar
CoreDumped
Gremlin
Posts: 177
Joined: Sun Aug 05, 2007 3:55 pm
x 14

Re: PhysX vehicle wheel issues

Post by CoreDumped »

Solved.

I made sure that the chasis and the wheels are being updated at the same frame but the same issue still existed.

I moved one front wheel up (so that it doesn't touch the ground) and the other front wheel to the middle (like a tri-car). the wheel that was not touching the ground was in the right place. Only the ones that had ground contact were getting moved back. So I was obviously doing something wrong in the wheel update code.

If any of you are using parts of the code that came along with the training program in the physx sdk, the following change should fix the problem

change:

Code: Select all

		if (s && wcd.contactForce > -1000)
		{
			pose.t = wcd.contactPoint;
			pose.t -= dir * r;	//go from contact pos to center pos.
to:

Code: Select all

		if (s && wcd.contactForce > -1000) {
			pose.t = p0 + dir * st;
			pose.t.y = wcd.contactPoint.y;
			pose.t -= dir * r;	//go from contact pos to center pos.
Post Reply