- Home /
How to acquire and use WheelJoint2D jointSpeed in my own formula
I have created 2D car (side view) with two wheels using WheelJoint2D. It says that they have they own parameter jointSpeed, but how do I acquire it? I am trying to create more in-Depth method of powering wheels using edited code from my 3D project, with multiple gears and torque curve, but to do that, I need to calculate EngineRPM using wheel rpm, which in this case could be jointSpeed (degrees/sec) which could then be recalculated into (rotations per minute) What should I put as wheel rpm? Should I getComponent.WheelJoint2D.jointSpeed and then * 360/60 them to get RPM? My code below worked okay in 3D game with wheel colliders, but I can't get it working in this 2d project
void FixedUpdate() {
FrontWheel.AddTorque(input * TorqueCurve.Evaluate(EngineRPM) * gearRatio[currentGear] * finalDrive);
RearWheel.AddTorque(input * TorqueCurve.Evaluate(EngineRPM) * gearRatio[currentGear] * finalDrive);
CarBody.AddTorque(input * carTorque * Time.fixedDeltaTime);
EngineRPM = Mathf.Abs(((FrontWheel.rpm) * finalDrive * gearRatio[currentGear] )* input);
if (EngineRPM > maxRPM)
{
EngineRPM = maxRPM;
}
}
Your answer
Follow this Question
Related Questions
How do i get a reverse rotation happening on right click down 1 Answer
Set connected Rigidbody 2D to a WheelJoint2D via script. 0 Answers
How can I make a wheel spin more freely using joints in Unity? 0 Answers
Rigidbody2D rotation spinning wildly when attaching by joint to another Rigidbody2D 0 Answers