Advertisement
Guest User

RelativPos

a guest
Dec 5th, 2015
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.88 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class DrawRelativePos : MonoBehaviour
  5. {
  6.     public Rigidbody2D playerRigidBody;
  7.     public Rigidbody2D objectRigidBody;
  8.  
  9.     Rigidbody2D rig;
  10.  
  11.     // Use this for initialization
  12.     void Start()
  13.     {
  14.         rig = this.GetComponent<Rigidbody2D>();
  15.     }
  16.  
  17.     // Update is called once per frame
  18.     void Update()
  19.     {
  20.         float angle = GetAngleToPlayer();
  21.         rig.MoveRotation(angle);
  22.         string str = "angle: " + angle;
  23.         print(str);
  24.     }
  25.  
  26.    float GetDistanceToPlayer()
  27.     {
  28.         float dist = Vector2.Distance(playerRigidBody.transform.position, objectRigidBody.transform.position);
  29.         return dist;
  30.     }
  31.  
  32.     float GetAngleToPlayer()
  33.     {
  34.         float angle = Vector2.Angle(playerRigidBody.transform.position, objectRigidBody.transform.position);
  35.         return angle;
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement