крч я захотел сделать трактор на котором можно было ехать но тут такоевот скрипт: using System.Collections; using System.Collections.Generic; using UnityEngine;
public class CarController : MonoBehaviour { public float speed = 10.0f; public float steeringAngle = 4.0f; public Transform [] wheels; public float wheelRotationSpeed = 100.0f; private float currentSpeed;
// Getting the speed and changing the position and rotation of the car currentSpeed = verticalInput * speed; transform.position += transform.forward * currentSpeed * Time.deltaTime; transform.Rotate(Vector3.up, horizontalInput * steeringAngle);
// Using the brake when pressing the Space key if (Input.GetKey( KeyCode.Space )) { currentSpeed = Mathf.Lerp(currentSpeed, 0, Time.deltaTime * 2); }
// Turning all the wheels for (int i = 0; i < wheels.Length; i++) { wheels[i].Rotate(Vector3.right * currentSpeed * Time.deltaTime * wheelRotationSpeed); } } }
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CarController : MonoBehaviour
{
public float speed = 10.0f;
public float steeringAngle = 4.0f;
public Transform [] wheels;
public float wheelRotationSpeed = 100.0f;
private float currentSpeed;
void Update()
{
// Getting horizontal and vertical input
float horizontalInput = Input.GetAxis("Horizontal");
float verticalInput = Input.GetAxis("Vertical");
// Getting the speed and changing the position and rotation of the car
currentSpeed = verticalInput * speed;
transform.position += transform.forward * currentSpeed * Time.deltaTime;
transform.Rotate(Vector3.up, horizontalInput * steeringAngle);
// Using the brake when pressing the Space key
if (Input.GetKey( KeyCode.Space ))
{
currentSpeed = Mathf.Lerp(currentSpeed, 0, Time.deltaTime * 2);
}
// Turning all the wheels
for (int i = 0; i < wheels.Length; i++)
{
wheels[i].Rotate(Vector3.right * currentSpeed * Time.deltaTime * wheelRotationSpeed);
}
}
}