Advertisement
Guest User

Untitled

a guest
Oct 25th, 2014
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.49 KB | None | 0 0
  1.     void Aiming()
  2.     {
  3.         mousePosInScene = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, -startPos.z));
  4.         mousePosInScene.z = startPos.z - 0.171f;
  5.  
  6.         float weaponDotProduct = Vector3.Dot((weaponAnkor.transform.position - weaponCenter.transform.position).normalized, (gameObject.transform.rotation * new Vector3(0, 0, 1)).normalized);
  7.         float mouseDotProduct = Vector3.Dot((mousePosInScene - weaponCenter.transform.position).normalized, (gameObject.transform.rotation * new Vector3(0, 0, 1)).normalized);
  8.  
  9.         if (weaponDotProduct > maxWeaponAimingAngle)
  10.         {
  11.             weaponRotationBackup = weaponCenter.transform.rotation;
  12.             headRotationBackup = headBone.transform.rotation;
  13.             headBone.transform.rotation = Quaternion.LookRotation(mousePosInScene - headBone.transform.position);
  14.             weaponCenter.transform.rotation = Quaternion.Lerp(weaponCenter.transform.rotation, Quaternion.LookRotation(mousePosInScene - weaponCenter.transform.position), 5f * Time.deltaTime);
  15.             weaponDotProduct = Vector3.Dot((weaponAnkor.transform.position - weaponCenter.transform.position).normalized, (gameObject.transform.rotation * new Vector3(0, 0, 1)).normalized);
  16.             if (weaponDotProduct <= maxWeaponAimingAngle)
  17.             {
  18.                 headBone.transform.rotation = headRotationBackup;
  19.                 weaponCenter.transform.rotation = weaponRotationBackup;
  20.             }
  21.         }
  22.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement