Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MoveTowardsPoint() {
- float CarX, CarY; //car position
- float DestX, DestY; //destination position (screen touch?)
- float CarSpeed; //current speed of car, control using acceleration or whatever
- float Angle = atan2(DestY - CarY, DestX - CarX); //angle between car and destination co-ordinates
- float NewX = CarX + (Math.Cos(Angle) * CarSpeed); //new x location
- float NewY = CarY + (Math.Sin(Angle) * CarSpeed); //new y location
- //then position car at these points and rotate sprite by Angle
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement