Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Vector3 dir = new Vector3(0,0,0);
- float x2 = targetPos.x;
- float x1 = transform.position.x;
- float y2 = targetPos.y;
- float y1 = transform.position.y;
- if(x2 - x1 >= 0)
- {
- if(Mathf.Abs(x2 - x1) < Mathf.Abs( (x2 - x1) - Screen.width )) dir.x = x2 - x1;
- else dir.x = (x2 - x1) - Screen.width;
- }
- else
- {
- if(Mathf.Abs(x2 - x1) < Mathf.Abs( (x2 - x1) + Screen.width )) dir.x = x2 - x1;
- else dir.x = (x2 - x1) + Screen.width;
- }
- if(y2 - y1 >= 0)
- {
- if(Mathf.Abs(y2 - y1) < Mathf.Abs( (y2 - y1) - Screen.height )) dir.y = y2 - y1;
- else dir.y = (y2 - y1) - Screen.height;
- }
- else
- {
- if(Mathf.Abs(y2 - y1) < Mathf.Abs( (y2 - y1) + Screen.height )) dir.y = y2 - y1;
- else dir.y = (y2 - y1) + Screen.height;
- }
- float rotZ = Mathf.Atan2(dir.x, dir.y) * Mathf.Rad2Deg;
- transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.Euler(0,0,-rotZ), rotationSpeed);
- rb.AddForceAtPosition(transform.up * Thrust, transform.position - transform.up);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement