Page 1 of 1

[SOLVED] PhysX vehicle wheel issues

Posted: Fri Feb 06, 2009 11:06 pm
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

Re: PhysX vehicle wheel issues

Posted: Sat Feb 07, 2009 6:08 am
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. :)

Re: PhysX vehicle wheel issues

Posted: Sat Feb 07, 2009 10:29 am
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.

Re: PhysX vehicle wheel issues

Posted: Sat Feb 07, 2009 4:18 pm
by CoreDumped
Thanks a lot guys. I'll try it out.

Re: PhysX vehicle wheel issues

Posted: Sat Feb 07, 2009 6:58 pm
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.