car movement unity 3d

Evil Elk answered on March 19, 2023 Popularity 5/10 Helpfulness 5/10

Contents


More Related Answers

  • camera follow script car unity
  • 3d player move in unity
  • unity 3d camera movement script
  • player movement unity 3d c#
  • basic movement script unity
  • car controller script unity
  • unity 3d movement script
  • car controller Unity
  • Unity basic movement script
  • player movement unity 3d script
  • unity player movement script 3d
  • player movement script unity
  • player movement script unity
  • Character Movement in Unity 3D

  • car movement unity 3d

    0

    using System.Collections;

    using System.Collections.Generic;

    using UnityEngine;

    public class move : MonoBehaviour

    {

    //vars

    public WheelCollider[] w;

    public Rigidbody rb;

    public GameObject com;

    public float speed = 100;

    public float trun = 45;

    public float maxspeed = 100f;

    public float speedpower;

    void Start()

    {

    //centerOfMass

    rb.centerOfMass = com.transform.localPosition;

    }

    void FixedUpdate()

    {

    speedpower = Input.GetAxis("Vertical");

    // for max and min speed

    speedcon();

    //movement

    movement();

    }

    void movement()

    {

    //forward and back

    foreach (var wheel in w)

    {

    wheel.motorTorque = speed * 5 / 4;

    }

    //truning

    for (int i = 0; i < w.Length; i++)

    {

    if (i < w.Length)

    {

    w[i].steerAngle = Input.GetAxis("Horizontal") * trun;

    }

    }

    }

    void speedcon()

    {

    max();

    min();

    }

    void max()

    {

    if (speed > maxspeed)

    {

    speed = maxspeed;

    }

    else

    {

    speed += speedpower;

    }

    }

    void min()

    {

    if (speed < 0)

    {

    speed = 0f;

    }

    else

    {

    speed += speedpower;

    }

    }

    }

    Popularity 5/10 Helpfulness 5/10 Language whatever
    Source: Grepper
    Tags: 3d whatever
    Link to this answer
    Share Copy Link
    Contributed on Mar 19 2023
    Evil Elk
    0 Answers  Avg Quality 2/10


    X

    Continue with Google

    By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
    X
    Grepper Account Login Required

    Oops, You will need to install Grepper and log-in to perform this action.