- Home /
How to set current position to previous postion
Hi all,
I m creating one car race game when my car hit the side walls its getting struck i want to set my car position back to its previous position how to do that can any one help me
please
thanks
Answer by Graham-Dunnett · Nov 16, 2012 at 03:57 PM
In your game script, have a variable that keeps the position of the car. In Update() decide if the car is still under control or not. If it is under control, then update the variable. If the car is skidding or crashing then don't update the variable. If the car has finally crashed and come to a halt, then change the position of the car to the last one you stored. In pseudo-code:
Update() {
if car is under control
last_position = position;
if car is skidding or crashing
play some kind of warning sound
if car has crashed
let player know to drive more slowly
position = last_position
}
Note - this is not Javascript or c# - it is meant to illustrate the logic you will need to implement.
Thanks for quick replay can u please write code for me because i m new to this
Your answer
![](https://koobas.hobune.stream/wayback/20220613083953im_/https://answers.unity.com/themes/thub/images/avi.jpg)