Hi again!
Thanks for the advice!
The code is the default one in CarUserControl, found on the Standard Assets pack:
private void FixedUpdate()
{
// pass the input to the car!
float h = CrossPlatformInputManager.GetAxis("Horizontal");
float v = CrossPlatformInputManager.GetAxis("Vertical");
#if !MOBILE_INPUT
float handbrake = CrossPlatformInputManager.GetAxis("Jump");
m_Car.Move(h, v, v, handbrake);
Debug.Log(h +" " +v + " " + handbrake);
#else
m_Car.Move(h, v, v, 0f);
#endif
}
This calls the Move function on CarController, also from the Standard Assets pack:
public void Move(float steering, float accel, float footbrake, float handbrake)
{
for (int i = 0; i < 4; i++)
{
Quaternion quat;
Vector3 position;
m_WheelColliders[i].GetWorldPose(out position, out quat);
m_WheelMeshes[i].transform.position = position;
m_WheelMeshes[i].transform.rotation = quat;
}
//clamp input values
steering = Mathf.Clamp(steering, -1, 1);
AccelInput = accel = Mathf.Clamp(accel, 0, 1);
BrakeInput = footbrake = -1*Mathf.Clamp(footbrake, -1, 0);
handbrake = Mathf.Clamp(handbrake, 0, 1);
//Set the steer on the front wheels.
//Assuming that wheels 0 and 1 are the front wheels.
m_SteerAngle = steering*m_MaximumSteerAngle;
m_WheelColliders[0].steerAngle = m_SteerAngle;
m_WheelColliders[1].steerAngle = m_SteerAngle;
SteerHelper();
ApplyDrive(accel, footbrake);
CapSpeed();
//Set the handbrake.
//Assuming that wheels 2 and 3 are the rear wheels.
if (handbrake > 0f)
{
var hbTorque = handbrake*m_MaxHandbrakeTorque;
m_WheelColliders[2].brakeTorque = hbTorque;
m_WheelColliders[3].brakeTorque = hbTorque;
}
CalculateRevs();
GearChanging();
AddDownForce();
CheckForWheelSpin();
TractionControl();
}
The Axis are mapped to the usual arrow keys/ AWSD controls, which work fine. What I (unsuccesfully) do is create a Panel with UIButtons simulating the physical keys, adding the AxisTouchButton script to them (once again, it comes on the Standard Assets).
I have watched examples and tutorials in which this kind of “experiment” work, with no need to modify the scripts using the GetAxis function so they recognize the UIButtons. Just attach AxisTouchButton to your on-screen buttons, tweak the params a bit, and voilà. Since the scripts for controlling the cars are default ones, I hesitate to modify anything on them (and I don’t see myself able to replicate a full functioning system of controlling cars with torque, steering, etc…)
Any tip or hint to unlock this problem would be of great help, this is just the last step to have at least a playable demo.
Thank you in advance!