Question by
TaskiPoike · Jan 11 at 02:58 PM ·
2dunity 2dwheelbike
Im making a 2d unity game with a bike. I want to make it able to turn to left and right with wheel joints. Now i can only go right but now left. Please help me.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Pyörii : MonoBehaviour
{
public WheelJoint2D frontwheel;
public WheelJoint2D backwheel;
JointMotor2D motorFront;
JointMotor2D motorBack;
public float speedF;
public float speedB;
public float torqueF;
public float torqueB;
public bool TractionFront = true;
public bool TractionBack = true;
public float carRotationSpeed;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetAxisRaw("Vertical") > 0)
{
if (TractionFront)
{
motorFront.motorSpeed = speedF * -1;
motorFront.maxMotorTorque = torqueF;
frontwheel.motor = motorFront;
}
if (TractionBack)
{
motorBack.motorSpeed = speedF * -1;
motorBack.maxMotorTorque = torqueF;
backwheel.motor = motorBack;
}
}
else if (Input.GetAxisRaw("Vertical") < 0)
{
if (TractionFront)
{
motorFront.motorSpeed = speedB * -1;
motorFront.maxMotorTorque = torqueB;
frontwheel.motor = motorFront;
}
if (TractionBack)
{
motorBack.motorSpeed = speedB * -1;
motorBack.maxMotorTorque = torqueB;
backwheel.motor = motorBack;
}
}
else
{
backwheel.useMotor = false;
frontwheel.useMotor = false;
}
if (Input.GetAxisRaw("Horizontal") != 0)
{
GetComponent<Rigidbody2D>().AddTorque(carRotationSpeed * Input.GetAxisRaw("Horizontal") * -1);
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Virtual controller and fire bullet shot in 2D 0 Answers
Having Problems With Bounce Physics Material 0 Answers
Why do prefabs overlap each other? 0 Answers
Limited Rotation in a 2D Platformer 1 Answer