Guest User

Untitled

a guest
Oct 29th, 2015
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class shauldspading : MonoBehaviour
  5. {
  6. public Transform Player;
  7. public Transform Mouse;
  8.  
  9.  
  10.  
  11. // Use this for initialization
  12. void Start ()
  13. {
  14.  
  15. }
  16.  
  17. // Update is called once per frame
  18. void FixedUpdate ()
  19. {
  20. //var mousePos = Input.mousePosition;
  21. //Vector3 Mouse = Camera.main.ScreenToWorldPoint(mousePos);
  22.  
  23. float xTo, yTo;
  24. Vector3 pos = transform.position;
  25. xTo = Player.position.x + lengthdir_x(Mathf.Min(9,Vector3.Distance(Player.transform.position, Mouse.transform.position)), Mouse.position);
  26. yTo = Player.position.y + lengthdir_y(Mathf.Min (9, Vector3.Distance (Player.transform.position, Mouse.transform.position)), Mouse.position);
  27. pos.x += (xTo - pos.x) / 25;
  28. pos.y += (yTo - pos.y) / 25;
  29. transform.position = pos;
  30. }
  31.  
  32.  
  33. float lengthdir_x(float len, Vector3 dir)
  34. {
  35. dir = dir.normalized * len;
  36. return dir.x;
  37. }
  38. float lengthdir_y(float len, Vector3 dir)
  39. {
  40. dir = dir.normalized * len;
  41. return dir.y;
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment