Birdman Posted May 26, 2011 Share Posted May 26, 2011 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 Quote Link to comment Share on other sites More sharing options...
Admin Posted May 27, 2011 Share Posted May 27, 2011 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 Quote Link to comment Share on other sites More sharing options...
Birdman Posted May 27, 2011 Author Share Posted May 27, 2011 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. Quote Link to comment Share on other sites More sharing options...
Josh Posted May 28, 2011 Share Posted May 28, 2011 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. Quote 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 More sharing options...
Birdman Posted May 30, 2011 Author Share Posted May 30, 2011 Yes you are right, this works too: GetBodyVelocity(chassis,0) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.