Question by
waleedqr · Oct 14, 2021 at 06:45 PM ·
wheelcollider
what's the problem with tiers ?
that's my Code:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class CarDrive : MonoBehaviour { public float WheelTorque; public float brakeTorque;
[Space(10)]
public WheelCollider FRwheel;
public WheelCollider BRwheel;
public WheelCollider FLwheel;
public WheelCollider BLwheel;
[Space (10)]
public Transform FRwheel_transform;
public Transform BRwheel_transform;
public Transform FLwheel_transform;
public Transform BLwheel_transform;
private void FixedUpdate()
{
if (Input.GetKey(KeyCode.W))
{
DriveFoward();
}
if(Input.GetKeyUp(KeyCode.W))
{
ResetWheelRotation();
}
if (Input.GetKey(KeyCode.S))
{
DriveBack();
}
if (Input.GetKey(KeyCode.D))
{
TurnRight();
}
if(Input.GetKeyUp(KeyCode.D))
{
ResetWheelRotation();
}
if (Input.GetKey(KeyCode.A))
{
TurnLeft();
}
if(Input.GetKeyUp(KeyCode.A))
{
ResetWheelRotation();
}
if (Input.GetKey(KeyCode.Space))
{
Stop();
}
ApplyWheelRotation (FRwheel, FRwheel_transform);
ApplyWheelRotation (BRwheel, BRwheel_transform);
ApplyWheelRotation (FLwheel, FLwheel_transform);
ApplyWheelRotation (BLwheel, BLwheel_transform);
}
private void DriveFoward()
{
FRwheel.motorTorque = WheelTorque;
BRwheel.motorTorque = WheelTorque;
FLwheel.motorTorque = WheelTorque;
BLwheel.motorTorque = WheelTorque;
FRwheel.brakeTorque = 0;
BRwheel.brakeTorque = 0;
FLwheel.brakeTorque = 0;
BLwheel.brakeTorque = 0;
}
private void DriveBack()
{
FRwheel.motorTorque = -WheelTorque;
BRwheel.motorTorque = -WheelTorque;
FLwheel.motorTorque = -WheelTorque;
BLwheel.motorTorque = -WheelTorque;
FRwheel.brakeTorque = 0;
BRwheel.brakeTorque = 0;
FLwheel.brakeTorque = 0;
BLwheel.brakeTorque = 0;
}
private void TurnRight()
{
FRwheel.steerAngle = 45;
FLwheel.steerAngle = 45;
}
private void TurnLeft()
{
FRwheel.steerAngle = -45;
FLwheel.steerAngle = -45;
}
private void ResetWheelRotation()
{
FRwheel.steerAngle = 0;
FLwheel.steerAngle = 0;
}
private void Stop()
{
FRwheel.brakeTorque = brakeTorque;
BRwheel.brakeTorque = brakeTorque;
FLwheel.brakeTorque = brakeTorque;
BLwheel.brakeTorque = brakeTorque;
}
private void ApplyWheelRotation(WheelCollider WheelCollider, Transform WheelTransform) { Vector3 position; Quaternion rotation;
WheelCollider. GetWorldPose (out position, out rotation);
WheelTransform.rotation = rotation;
WheelTransform.position = position;
}
}
-لقطة-الشاشة-في-م.png
(225.3 kB)
Comment
Your answer
Follow this Question
Related Questions
Wheel Collider violently shaking 2 Answers
Wheelcolliders are sliding. 0 Answers
My vehicle is not moving backwards with WheelCollider 0 Answers
WheelCollider Docs Tutorial issue 0 Answers