I am making an fps parkour game and I decided to add a motorcycle. I have created a mounting system and put wheel colliders with a script that added torque to them. I have only tried to make the forward and backward movement first, and I am able to move forward but very slowly no matter how I change the MotorForce or the mass of the rigid body on my motorbike. For some reason, the motorcycle would move fast in a direction if I looked down from the mounted position.
Here is the mounting and driving script:
public class InteractionManager : MonoBehaviour
{
public GameObject Motorbike;
public GameObject Player;
private Rigidbody rb;
public Transform playerTransform;
public static bool ridingMotorBike = false;
public float MotorForce;
public WheelCollider WheelColF;
public WheelCollider WheelColB;
// Start is called before the first frame update
void Start()
{
rb = Motorbike.GetComponent<Rigidbody>();
}
// Update is called once per frame
void FixedUpdate()
{
float distance = Vector3.Distance(transform.position, Motorbike.transform.position);
Vector3 dir = (Motorbike.transform.position - transform.position).normalized;
float dot = Vector3.Dot(dir, transform.forward);
if (dot > .6 && distance <= 3 && !ridingMotorBike && Input.GetKeyDown("e"))
{
ridingMotorBike = true;
}
else if (ridingMotorBike)
{
Player.transform.SetParent(Motorbike.transform);
Player.transform.localPosition = new Vector3(0, 0, 0);
if (Input.GetKeyDown("e"))
{
ridingMotorBike = false;
Player.transform.localPosition = new Vector3(0, 0, 1);
playerTransform.parent = null;
}
rb.velocity = Vector3.zero;
rb.angularVelocity = Vector3.zero;
float v = Input.GetAxis("Vertical") * 600;
WheelColF.motorTorque = v;
WheelColB.motorTorque = v;
}
}
}
Any help would be appreciated!