- Home /
Vehicle Script not turning left and right!
My vehicle enter/exit script is not turning left and right, i am using the realistic fps prefab. If you can help me, i'll be very happy, you'll also get your name in the credits on steam release. :)
Here is the current car script var topSpeed = 120; var weight : int = 10; var tireTraction : int = 3; var slowDown = false;
function Update()
{
//controller = GetComponent(CharacterController);
var controller : CharacterController = GetComponent(CharacterController);
var moveDirection = transform.TransformDirection(Vector3.forward);
var curSpeed = vehicleSpeed * Input.GetAxis("Joystick Move X");
transform.Rotate(0, Input.GetAxis("Joystick Move Y") * tireTraction, 0);
if (Input.GetKey("w") || Input.GetKey("up"))
{
slowDown = false;
if (vehicleSpeed < topSpeed)
{
vehicleSpeed += 1 * Time.deltaTime * conversionMetrics;
}
}
if (Input.GetKeyUp("w") || Input.GetKeyUp("up") || Input.GetKeyUp("s") || Input.GetKeyUp("down") || Input.GetKeyUp("space"))
{
slowDown = true;
}
if (slowDown == true)
{
if (vehicleSpeed > 0)
{
vehicleSpeed -= 1 * Time.deltaTime * conversionMetrics;
if (vehicleSpeed == 3)
{
slowDown = false;
vehicleSpeed = 0;
}
}
}
if (Input.GetKey("s") || Input.GetKey("down"))
{
slowDown = false;
if (vehicleSpeed > 0)
{
vehicleSpeed -= 5 * Time.deltaTime * conversionMetrics;
if (vehicleSpeed == 3)
{
slowDown = false;
vehicleSpeed = 0;
}
}
}
if (Input.GetKey("space"))
{
slowDown = false;
if (vehicleSpeed > 0)
{
vehicleSpeed -= 12 * Time.deltaTime * conversionMetrics;
if (vehicleSpeed == 3)
{
slowDown = false;
vehicleSpeed = 0;
}
}
}
// Apply weight
moveDirection.y -= weight * Time.deltaTime;
// Move the controller
controller.SimpleMove(moveDirection * vehicleSpeed);
if (vehicleSpeed < 0)
{
vehicleSpeed = 0;
slowDown = false;
}
}
I see no implementation for it. So have you even tried? As well as the fact that there are a couple solutions to be found on this site. Search before asking.
I can't see where you have declared vehicleSpeed, and I can only assume it's a float value, and that is assigned to the car's velocity.magnitude.
Also, I see no code where you have the input of the keys "a" and "d" for turning. Perhaps that's the problem.
The vehicle speed is at the top @isfrseirra - Didn't seem to copy over... Anyway thanks, it wasn't implemented the "a" and "d", I fixed it though ;)
Your answer
Follow this Question
Related Questions
Car Movement Script 4 Answers
Car movement script ? 1 Answer
Vehicle/car/ Movement 0 Answers
Strange behavior with the Unity car? 0 Answers
How to toggle a key for a car to go forward or backward? 1 Answer