- Home /
Car turns without going forward
Hello, I have been learning character controls and I have got down the moving part. That works fine, but what I want is:
For example: I'm driving forward on a street. And then i stop, And i try to turn. My car can turn without going forward.. Does anyone know how to stop this?
Thanks In advance!
My Code For Moving Is:
var speed = 3.0;
var rotateSpeed = 3.0;
function Update()
{
var controller : CharacterController = GetComponent(CharacterController);
//rotate around y - axis
transform.Rotate(0, Input.GetAxis ("Mouse X") * rotateSpeed, 0);
//Move forward / backward
var forward = transform.TransformDirection(Vector3.forward);
var curSpeed = speed * Input.GetAxis ("Vertical");
controller.SimpleMove(forward * curSpeed);
}
Answer by robertbu · Mar 11, 2013 at 07:18 AM
Untested. It just checks to make sure that the forward speed is above some threshold before allowing the car to turn. I have no idea if '0.5' is a reasonable number for minTurnSpeed. You'll have to play with some values.
var speed = 3.0;
var rotateSpeed = 3.0;
var minTurnSpeed = 0.5;
function Update()
{
var controller : CharacterController = GetComponent(CharacterController);
//Move forward / backward
var forward = transform.TransformDirection(Vector3.forward);
var curSpeed = speed * Input.GetAxis ("Vertical");
//rotate around y - axis
if (curSpeed > minTurnSpeed)
transform.Rotate(0, Input.GetAxis ("Mouse X") * rotateSpeed, 0);
controller.SimpleMove(forward * curSpeed);
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613094204im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Cloud recognition in Vuforia 0 Answers
Simple car problem 0 Answers
Smoother Turning (New guy here, hi) 1 Answer
Unlimited Road car AI 0 Answers