1
\$\begingroup\$

I'm fairly new to Unity and i'm struggling to find some answers. Every car script and wheelCollider tutorial I can find is based in the horizontal and vertical axis and that works great. But I'd like to move the car while holding a trigger and brake the car while holding another trigger (ps4 controller. Inputs are already mapped and working), but I need some help on that.

This is the part of the script that handles the acceleration:

 float motor = maxMotorTorque * Input.GetAxis("Vertical");
 foreach (AxleInfo axleInfo in axleInfos) {
     axleInfo.leftWheel.motorTorque  = motor;
     axleInfo.rightWheel.motorTorque = motor;
 }

Is there anyone that can point me in the right direction or possibly provide some example scripts?

Thanks in advance.

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

See the trigger pressing input. If it's pressing keep the value in a Boolean.

The code will be like:

if(pressing_trigger) //trigger values are [0-1] so pressing_trigger is true when trigger value is greater than 0 (zero).
{
//your acceleration code
}

Go to xbox/ps trigger setup

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .