- 176
- 294
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Подумал может кому-то нужен мой еще один говнокод
Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MovCar : MonoBehaviour
{
public Rigidbody theRB;
public float forwardAccel = 8f, reverseAccel = 4f, maxSpeed = 50f, turnStrength = 180f, gravityForce = 10f, dragOnGround = 3f;
public LayerMask whatIsGround;
public float groundRayLength = .5f;
public Transform groundRayPoint;
pritave float speedInput, turnInput;
private bool grounded;
void Start()
{
theRB.transform.parent = null;
}
void Update()
{
speedInput = 0f;
if (Input.GetAxis("Vertical") > 0)
{
speedInput = Input.GetAxis("Vertical") * forwardAccel * 1000f;
} else if (Input.GetAxis("Vertical") < 0)
{
speedInput = Input.GetAxis("Vertical") * reverseAccel * 1000f;
}
turnInput = Input.GetAxis("Horizontal");
if(grounded)
{
transform.rotation = Queternion.Euler(transform.rotation.eulerAngles + new Vector3(0f, turnInput * turnStrength * Time.deltaTime* Input.GetAxis("Verical"), 0f));
}
transform.position = theRB.transform.position;
}
private void FixedUpdate()
{
grounded = false;
RaycastHit hit;
if(Physics.Raycast(groundRayPoint.position, -transform.up, out hit, groundRayLength, whatIsGround))
{
grounded = true;
transform.rotation = Queternion.FromToRotation(transform.up, hit.normal) * transform.rotation;
}
if(grounded)
{
theRB.drag = dragOnGround;
if (Mathf.Abs(speedInput) > 0)
{
theRB.AddForce(transform.forward * speedInput);
}
}
else
{
theRb.drag = 0.1f;
theRb.AddForce(Vector3.up * -gravityForce * 100f);
}
}
}
Файлик будет закреплен