Jump to content

Vehicle Brake and Speed?


Birdman
 Share

Recommended Posts

Hello,

 

Since i can't use Joystick for a Driving LUA demo, i made a c++ code that have a running vehicle based on few posts i saw and a rewrite of the original LUA i had.

 

Im applying Torque to the vehicle this way:

 

               TVehicle veh=CreateVehicle(chassis);
               .....

               TMesh tire[4];
               .....

               // Torque
	AddTireTorque(veh, 0, -1);
               if (KeyDown(KEY_UP))
			{
				if (!TireIsAirborne(tire[0])) AddTireTorque(veh, -24, 0);
				if (!TireIsAirborne(tire[1])) AddTireTorque(veh, -24, 1);
			}
	if (KeyDown(KEY_DOWN))
			{
				if (!TireIsAirborne(tire[0])) AddTireTorque(veh, +24, 0);
				if (!TireIsAirborne(tire[1])) AddTireTorque(veh, +24, 1);
			}

 

I can't seem to find a way to check Tire actual torque to be able apply negative Torque until vehicle is stopped.

I'm applying torque only to wheels 0 and 1 becouse i want a front-wheel drive vehicle.

 

My idea was to make something like this (Anyway applying 0 torque will do nothing, but if apply negative it will go backwards after stopped):

 

       // BRAKE
               if (KeyDown(KEY_SPACE))
			{
				if (!TireIsAirborne(tire[0])) AddTireTorque(veh, 0, 0);
				if (!TireIsAirborne(tire[1])) AddTireTorque(veh, 0, 1);
			}

Also Is there a way to calculate some kind of speed with raycastvehicle?

 

Anybody implemented some kind of Engine to do gears and stuff?

 

Thanks a lot in advance

Link to comment
Share on other sites

I would use a brake force, and just keep applying it until it stops. To keep it from going negative, you could do multiply the vehicle's velocity on it's own z axis by some number between 0 and -1, and that will cause it to gradually slow and stop.

 

So you're adding negative torque to make the car slower instead of faster.

 

The calculation that takes the distance traveled and turns it into rotation is below. The reverse of this equation would take the tire rotation speed and convert it to ground speed:

Local c#=2.0*Pi*radius
lastposition=tformpointm(lastposition,Null,vehicle.parent.nextmat)
dist = position.z - lastposition.z
turnspeed = dist / c * 360.0

 

 

Link to comment
Share on other sites

I would use a brake force, and just keep applying it until it stops. To keep it from going negative, you could do multiply the vehicle's velocity on it's own z axis by some number between 0 and -1, and that will cause it to gradually slow and stop.

 

Thanks for your Repply, i don't know where to get the velocity Vector, do you have an idea on how will this be?

 

I Tried doing something like this but it crashes inside GetBodyVelocity, either using the Chassis object or the vehicle object.

appliedvelocity = (0.2 * GetBodyVelocity(veh,1).Z)*(-1);

 

Finally CalcBodyVelocity worked with this, idk why GetBodyVelocity Crashes.

 

 

Edit: Btw checking the vehicle script i found this code that is used for the decals:

						speed = math.abs(self.model:GetVelocity(0).z)
					speed = (speed - 4) / 120.0
					speed = Clamp( speed, 0, 1 ) * 0.05

I will try to convert this to C++ to use to calculate speed.

Link to comment
Share on other sites

The vehicle itself is a joint. The chassis is the body, and you should be able to retrieve the velocity with no problem. You can retrieve the velocity in local space to make your job easier.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...