I have a track of 2.5 units. I wanted my car to move every time such that the track is covered in 3 moves when it travels from extreme left to extreme right and accordingly it should calculate the X position to reach at every move at any point of the road.
Leftmost end of the track is at -1.45
Righmost is ar 1.05
As far as I can understand, amountofmovement
should be 2.5/3
if track of width 2.5 is divided in three car moves from one end to the other but 2.5/3 will result in 0.83 which is not available to be moved in one particular direction since my range of track is from -1.45 to 1.05.
2.5/10 is what I found by hit and try but to understand it in a better way, what exactly shall be the concept? Here is my code:
amountofmovement = 2.5/10;
which results in amount of movement = 0.25
this.transform.position = new Vector3 (this.transform.position.x - amountofmovement, this.transform.position.y, this.transform.position.z);
I can't give you an code example, but what you did is perfectly right. When you Start at -1.45 and move the car three times by +0.83 you will reach +1.05. So you covered a distance of 2.5 in three steps.
Here are the x positions:
x (Start): -1.45
x (after first move): -0.62
x (after second move): 0.21
x (after third move/Finish): 1.05
(All values are rounded so please calculate them by yourself)