Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.51 KB | None | 0 0
  1. MoveTowardsPoint() {
  2.  
  3.     float CarX, CarY;       //car position
  4.     float DestX, DestY;     //destination position (screen touch?)
  5.     float CarSpeed;         //current speed of car, control using acceleration or whatever
  6.  
  7.     float Angle = atan2(DestY - CarY, DestX - CarX);    //angle between car and destination co-ordinates
  8.  
  9.     float NewX = CarX + (Math.Cos(Angle) * CarSpeed);   //new x location
  10.     float NewY = CarY + (Math.Sin(Angle) * CarSpeed);   //new y location
  11.  
  12.     //then position car at these points and rotate sprite by Angle
  13.  
  14.  
  15.  
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement