C# Исходник [Unity3D] Движение машинок для аркадных гонок.

Savok

Потрачен
Автор темы
178
292
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
car (1).gif

Подумал может кому-то нужен мой еще один говнокод​
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);
        }
    }
}
Файлик будет закреплен
 

Вложения

  • MovCar.cs
    1.8 KB · Просмотры: 6
  • Bug
  • Нравится
Реакции: kuzheren и Z3roKwq

LiL STANLEY

Активный
146
43
Посмотреть вложение 203733
Подумал может кому-то нужен мой еще один говнокод
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);
        }
    }
}
Файлик будет закреплен
Лучше зафиксируй камеру в одном положении,эта спермотряска никому не понравится.
 
  • Эм
Реакции: Savok

Savok

Потрачен
Автор темы
178
292
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Лучше зафиксируй камеру в одном положении,эта спермотряска никому не понравится.
Если ты не знаешь, для реалистики почти во все аркадных играх делают тресящуюся камеру.
Если такой умный, сделай сам как тебе надо или попроси.
 
  • Нравится
Реакции: XRLM

LiL STANLEY

Активный
146
43
Если ты не знаешь, для реалистики почти во все аркадных играх делают тресящуюся камеру.
Если такой умный, сделай сам как тебе надо или попроси.
че
реалистика в аркадах?

Если ты не знаешь, для реалистики почти во все аркадных играх делают тресящуюся камеру.
Если такой умный, сделай сам как тебе надо или попроси.
хочу посмотреть,сколько такая игра наберет скачиваний xd
 

Savok

Потрачен
Автор темы
178
292
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.