Guest User

Untitled

a guest
Jan 17th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1.  
  2.  
  3. var target : Transform; //Variable "target" wird durch ein reinzieh-Feld definiert
  4.  
  5.  
  6.  
  7. var smoothTime = 5;
  8.  
  9. var rotationTime = 0.2;
  10.  
  11. var xOffset : float = 1.0;
  12.  
  13. var yOffset : float = 1.0;
  14.  
  15.  
  16.  
  17.  
  18.  
  19. var look_speed = 0.2;
  20.  
  21. var look_distance = 5;
  22.  
  23.  
  24.  
  25. var mainCamera : Transform;
  26.  
  27.  
  28.  
  29. static var mouseposition_y : float;
  30.  
  31. static var mouseposition_x : float;
  32.  
  33.  
  34.  
  35. private var thisTransform : Transform;
  36.  
  37.  
  38.  
  39. var hitposition : Vector3;
  40.  
  41.  
  42.  
  43. function Start()
  44.  
  45. {
  46.  
  47. thisTransform = transform;
  48.  
  49. }
  50.  
  51.  
  52.  
  53. function Update ()
  54.  
  55. {
  56.  
  57.  
  58.  
  59. Debug.Log (hitposition);
  60.  
  61.  
  62.  
  63. }
  64.  
  65.  
  66.  
  67. function LateUpdate()
  68.  
  69. {
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77. //Raycast
  78.  
  79. var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition); //Ray erstellen
  80.  
  81. var hit : RaycastHit; //Hit erstellen, der uns gleich mit Daten über den "Einschlag" beliefert
  82.  
  83.  
  84.  
  85.  
  86.  
  87. if (Physics.Raycast(ray, hit))
  88.  
  89. {
  90.  
  91.  
  92.  
  93. var hitposition = (hit.point);
  94.  
  95.  
  96.  
  97. }
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105. var mouseposition_x = (ray.direction.x) ;
  106.  
  107. var mouseposition_y = (ray.direction.y) ;
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119. //Follow Player
  120.  
  121. thisTransform.position.x = Mathf.Lerp( thisTransform.position.x, target.position.x + xOffset + mouseposition_x * look_distance, Time.deltaTime * smoothTime);
  122.  
  123. thisTransform.position.y = Mathf.Lerp( thisTransform.position.y, target.position.y + yOffset + mouseposition_y * look_distance, Time.deltaTime * smoothTime);
  124.  
  125.  
  126.  
  127.  
  128.  
  129. //Rotation des targets (Player) wenn Maus auf der linken Seite ist
  130.  
  131. if (mouseposition_x > 0)
  132.  
  133. {
  134.  
  135. //rechts
  136.  
  137. target.transform.rotation = Quaternion.Slerp(target.transform.rotation, (Quaternion.AngleAxis(90, Vector3.up)),Time.deltaTime * rotationTime);
  138.  
  139.  
  140.  
  141.  
  142.  
  143. }
  144.  
  145. else
  146.  
  147. {
  148.  
  149. //links
  150.  
  151. target.transform.rotation = Quaternion.Slerp(target.transform.rotation, (Quaternion.AngleAxis(-90, Vector3.up)),Time.deltaTime * rotationTime);
  152.  
  153. }
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163. /*
  164.  
  165. Debug.Log (hitposition);
  166.  
  167. hitposition.y = 0;
  168.  
  169. hitposition.z = 0;
  170.  
  171.  
  172.  
  173. target.transform.LookAt(hitposition);
  174.  
  175. */
  176.  
  177.  
  178.  
  179. }
Add Comment
Please, Sign In to add comment