Page 1 of 1

tank rears up as it accelerates

Posted: Tue Nov 01, 2011 11:19 am
by speciesUnknown
Hey, i have a tank with a suspension. It's derived from the tankinput class in the demos.

Here is the code I use for setup:

Code: Select all

		public BepuTankInput(Vector3 position, ConvexHull shape, Space owningSpace)
		{
			this.Space = owningSpace;
			RigidTransform t = RigidTransform.Identity;

			//				shape.CollisionInformation.LocalPosition = new Vector3(0, -.7f, 0);
			shape.Position = (position); //At first, just keep it out of the way.

			Vehicle = new BEPUphysics.Vehicle.Vehicle(shape);

			var bb = shape.CollisionInformation.BoundingBox;

			#region RaycastWheelShapes

			//The wheel model used is not aligned initially with how a wheel would normally look, so rotate them.
			MaximumDriveForce = 450;
			BaseSlidingFriction = 0.995f;
			float sus_damping = 100f;
			float sus_stiffness = 400f;

			int num_wheels_per_side = 4;
			int one_over_nwps = 1 / num_wheels_per_side;

			// positions relative to centre of tank of wheels on each side
			float[] positions = { -1f, -0.5f, 0f, 0.5f, 1f };

			Matrix wheelGraphicRotation = Matrix.CreateFromAxisAngle(Vector3.Forward, MathHelper.PiOver2);
			foreach(var p in positions)
			{
				var toAdd = new Wheel(
					new RaycastWheelShape(.375f, wheelGraphicRotation),
					new WheelSuspension(sus_stiffness, sus_damping, Vector3.Down, 1f, new Vector3(-4.3f, -0.5f, p * 4f) ),
					new WheelDrivingMotor(10, MaximumDriveForce, MaximumDriveForce),
					new WheelBrake(BaseSlidingFriction, BaseSlidingFriction, 1.0f),
					new WheelSlidingFriction(0.5f, 0.6f)
				);

				Vehicle.AddWheel(toAdd);
				leftTrack.Add(toAdd);
			}

			foreach (var p in positions)
			{
				var toAdd = new Wheel(
					new RaycastWheelShape(.375f, wheelGraphicRotation),
					new WheelSuspension(sus_stiffness, sus_damping, Vector3.Down, 1f, new Vector3(4.1f, -0.5f, p * 4f)),
					new WheelDrivingMotor(10, MaximumDriveForce, MaximumDriveForce),
					new WheelBrake(BaseSlidingFriction, BaseSlidingFriction, 1.0f),
					new WheelSlidingFriction(0.5f, 0.6f)
				);

				Vehicle.AddWheel(toAdd);
				rightTrack.Add(toAdd);
			}

			#endregion

			foreach (Wheel wheel in Vehicle.Wheels)
			{
				//This is a cosmetic setting that makes it looks like the car doesn't have antilock brakes.
				wheel.Shape.FreezeWheelsWhileBraking = true;

				//By default, wheels use as many iterations as the space.  By lowering it,
				//performance can be improved at the cost of a little accuracy.
				wheel.Suspension.SolverSettings.MaximumIterations = 4;
				wheel.Brake.SolverSettings.MaximumIterations = 4;
				wheel.SlidingFriction.SolverSettings.MaximumIterations = 4;
				wheel.DrivingMotor.SolverSettings.MaximumIterations = 4;
			}
		}
When the user first hits the throttle, the tank rears up, and this seems to make it impossible to steer for a few seconds, until the tank reaches speed. There are 5 wheels on each side, but im going to later derive the wheels from the model file so that I can properly match the wheels to the suspension. I've experimented with a whole range of suspension stiffness and damping factors, but it seems that the most important factors are the engine force and the weight of the vehicle.

How can I avoid a vehicle rearing up (all wheels appear to still be on the ground, but the front ones arent getting good contact) or alternatively, ensure I can still steer while the vehicle is "reared" (the rearing behaviour actually looks quite cool, i'd prefer to be able to keep it in but not have any steering difficulties)

Re: tank rears up as it accelerates

Posted: Tue Nov 01, 2011 6:53 pm
by Norbo
This is an expected physical effect that happens when an extremely powerful motor was put on a top-heavy object, so addressing those two core issues are the most direct ways to change the behavior.

To lessen the rear-up, you can change the local position of the collidable. This effectively offsets the center of mass. By setting the local position Y to 0.5 to 1 (positive, meaning the center of mass is going to be lower), most of the effect will go away.

The other approach is to weaken the acceleration.

Steering should stay pretty controllable until only a couple of wheels have solid traction. The maximum force the wheels can apply is capped by friction, so greater weight on a wheel increases its traction- but if the whole tank is at a 50 degree angle to the ground, it will still be difficult.