Guest User

RelativPos

a guest
Dec 5th, 2015
68
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

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×