- Home /
Truck moves sideways when using transform.forward,When i translate my truck with transform.forward it goes sideways
unless i don't rotate my truck at the start with my script or in my scene, it will go forward however if i do rotate it, it will go sideways
To spawn the truck:
GameObject truck = Instantiate(TruckPrefab, TruckStartPositions[0]); truck.transform.eulerAngles = new Vector3(0, 90, 0);
Script on the truck:
void Update() { if (transform.GetChild(1).eulerAngles.z > -45 && transform.GetChild(0).eulerAngles.z < 45 && transform.GetChild(1).eulerAngles.x > -30 && transform.GetChild(0).eulerAngles.x < 30) { Velocity = transform.forward Speed Time.deltaTime; } transform.Translate(Velocity); ApplyDrag();
if (Speed < _maxSpeed)
{
Speed += 0.1f;
}
void ApplyDrag()
{
Velocity = Velocity * (1 - Time.deltaTime * _dragOnGround);
}
},Unless i don't rotate my truck in the scene or in the script my truck goes forward, but when i do it goes sideways
GameObject truck = Instantiate(TruckPrefab, TruckStartPositions[0]); truck.transform.eulerAngles = new Vector3(0, 90, 0);
void Update() { if (transform.GetChild(1).eulerAngles.z > -45 && transform.GetChild(0).eulerAngles.z < 45 && transform.GetChild(1).eulerAngles.x > -30 && transform.GetChild(0).eulerAngles.x < 30) { Velocity = transform.forward Speed Time.deltaTime; } transform.Translate(Velocity); ApplyDrag();
if (Speed < _maxSpeed)
{
Speed += 0.1f;
}
void ApplyDrag()
{
Velocity = Velocity * (1 - Time.deltaTime * _dragOnGround);
}
}
Your answer
Follow this Question
Related Questions
I want a better explination than the one in unitys tutorial 2 Answers
Distribute terrain in zones 3 Answers
C# always move an object forward and still use physics 1 Answer
transform.forward makes my GameObject Disappear 0 Answers
How to combine movements of the transform.rotation and transform.position 1 Answer