Hi there, my first post :)
So I have a modified car script that I want to make it move more or less like a real car.
I have a car object that has an "arrow" as a child object. The arrow is positioned where the
"middle wheel" would be, sort of like on those old three-wheeled cars. The arrow rotates left and right
and I want to make the car move towards it's direction. I used AddForce to do this, but don't know how
to make it add force to the direction of the middle wheel. Hope I'm not too vague about my problem.
This is a very shortened script, the car moves fine and everything, but the original code had the car
rotate by on it's own, even when being still. Also I left out the whole movespeed, gear, and gas_pedal so the post isn't too cluttered.
Here's the shortened script:
using UnityEngine;
using System.Collections;
public class MicanjeCar4 : MonoBehaviour {
public Transform Car;
public Transform ArrowObjectRot;
public float movespeed = 5.0F;
public int gas_pedal = 0;
public int gear = 1;
void Start () {
arrowObjectRot = ArrowObjectRot.transform.localPosition;
}
void Update ()
{
if (Input.GetKey(addgas))
{
if (gas_pedal <= 100)
{
if (movespeed <= 0)
{
if (gear == 1) {
Car.rigidbody.AddForce(transform.forward * Time.deltaTime * movespeed, ForceMode.Acceleration);
gas_pedal += 1;
}
else {
isengine = false;
}
}
else {
Car.rigidbody.AddForce(transform.forward * Time.deltaTime * movespeed, ForceMode.Acceleration);
gas_pedal += 1;
}
}
else {
Car.rigidbody.AddForce(transform.forward * Time.deltaTime * movespeed, ForceMode.Acceleration);
}
}
else
{
if (gas_pedal > 0) {
Car.rigidbody.AddForce(transform.forward * Time.deltaTime * movespeed, ForceMode.Acceleration);
gas_pedal -= 1;
}
}
}
}
↧