As stated above, I’m looking for a simple way to duplicate my main player but add different inputs for his controls. I’m currently moving his motor torque with the “vertical axis” and his steering power with “horizontal axis”. Which, as far as I know, means uparrow, down arrow - right arrow, left arrow.
Just wondering how to create this duplicate player to control him with different inputs, if that makes sense. Any help appreciated.
Thanks man! I got really lucky and found a great script to separate my controllers. This is what it looks like now
/ Update is called once per frame
void FixedUpdate()
{
foreach (var wheel in wheels)
{
var vertical = 0;
if (Input.GetKey(KeyCode.UpArrow)) vertical = 1;
if (Input.GetKey(KeyCode.DownArrow)) vertical = -1;
wheel.motorTorque = vertical * motorPower;
}
{
for (int i = 0; i < wheels.Length; i++)
{
if (i < 2)
{
var horizontal = 0;
if (Input.GetKey(KeyCode.RightArrow)) horizontal = 1;
if (Input.GetKey(KeyCode.LeftArrow)) horizontal = -1;
wheels[i].steerAngle = horizontal * steerPower;
}
}
versus
foreach (var wheel in wheels)
{ var vertical = 0;
if (Input.GetKey(KeyCode.R)) vertical = 1;
if (Input.GetKey(KeyCode.C)) vertical = -1;
wheel.motorTorque = vertical * motorPower;
}
{
for (int i = 0; i < wheels.Length; i++)
{
if (i < 2)
{
var horizontal = 0;
if (Input.GetKey(KeyCode.G)) horizontal = 1;
if (Input.GetKey(KeyCode.D)) horizontal = -1;
wheels[i].steerAngle = horizontal * steerPower;
foreach (var wheel in wheels)
{ var vertical = 0;
if (Input.GetKey(KeyCode.R)) vertical = 1;
if (Input.GetKey(KeyCode.C)) vertical = -1;
wheel.motorTorque = vertical * motorPower;
}
{
for (int i = 0; i < wheels.Length; i++)
{
if (i < 2)
{
var horizontal = 0;
if (Input.GetKey(KeyCode.G)) horizontal = 1;
if (Input.GetKey(KeyCode.D)) horizontal = -1;
wheels[i].steerAngle = horizontal * steerPower;
}
Store the KeyCodes in variables. That way you can re-use the script for both players, instead of having to copy the entire thing. Also makes adding changes a lot easier.