#Unity Car movement

1 messages · Page 1 of 1 (latest)

rotund vapor
#

Hello, im trying to make a game where you have a car that is automatically going straight and you can control the directions. It is moving forward very slow, i dont know why. Here is the code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class WheelController : MonoBehaviour
{

[SerializeField] WheelCollider frontRight;
[SerializeField] WheelCollider frontLeft;
[SerializeField] WheelCollider backRight;
[SerializeField] WheelCollider backLeft;


public float acceleration = 500f;
public float breakingForce = 300f;
public float maxTurnAngle = 15f;
public Rigidbody rb;
public float forwardSpeed = 100f;

private float currentAcceleration = 0f;
private float currentBreakForce = 0f;
private float currentTurnAngle = 0f;


private void FixedUpdate()
{
   // currentAcceleration = acceleration * Input.GetAxis("Vertical");


  //  if (Input.GetKey(KeyCode.Space))
  //      currentBreakForce = breakingForce;
  //  else
   //     currentBreakForce = 0f;

    rb.AddForce(0, 0, forwardSpeed * Time.deltaTime);
    frontRight.motorTorque = forwardSpeed * 100 * Time.deltaTime;
    frontLeft.motorTorque = forwardSpeed * 100 * Time.deltaTime;
    

    frontRight.brakeTorque = currentBreakForce;
    frontLeft.brakeTorque = currentBreakForce;
    backRight.brakeTorque = currentBreakForce;
    backLeft.brakeTorque = currentBreakForce;

    currentTurnAngle = maxTurnAngle * Input.GetAxis("Horizontal");
    frontLeft.steerAngle = currentTurnAngle;
    frontRight.steerAngle = currentTurnAngle;
}

}

proper quartz
#

is it possible that your forwardSpeed value is not what you think it is? given that its public there is nothing preventing the value from being changed from outside the class

wary anvil
#

Why are you multiplying by time.deltatime for the motor torque

#

What is the problem? If the car is moving slow and you want it to move faster, increase the speed

proper quartz
silk dagger
wary anvil
proper quartz
rotund vapor
#

Holy

#

Forgot about this