SHARE
TWEET

RelativPos

a guest Dec 5th, 2015 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top