Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. // Gives the illusion of the camera being fixed in one place and rotating to face the player as they move
  2. // oPC the PC you want to apply the camera movement to
  3. // fFrameRate number of movements per second (governs how smooth the motion is)
  4. //
  5. // To setup a fixed camera position, place a waypoint with a unique tag in your area
  6. // Set the camera's tag as a LocalString "sFixedCamera" on the PC to let them know to use that camera
  7. // Set a LocalFloat "fFixedCamera" on the PC to set the camera's vertical position
  8. // Set "sFixedCamera" to "" to end the tracking
  9. void FixedCamera(object oPC, float fFrameRate = 30.0);
  10.  
  11.  
  12. vector GetVectorAB(object oA, object oB)
  13. {
  14. vector vA = GetPosition(oA);
  15. vector vB = GetPosition(oB);
  16. vector vDelta = (vA - vB);
  17. return vDelta;
  18. }
  19.  
  20. float GetHorizontalDistanceBetween(object oA, object oB)
  21. {
  22. vector vHorizontal = GetVectorAB(oA,oB);
  23. float fDistance = sqrt(pow(vHorizontal.x,2.0) + pow(vHorizontal.y,2.0));
  24. return fDistance;
  25. }
  26.  
  27. float GetDirection(object oTarget, object oPC)
  28. {
  29. vector vdTarget = GetVectorAB(oTarget,oPC);
  30. float fDirection = VectorToAngle(vdTarget);
  31. return fDirection;
  32. }
  33.  
  34.  
  35. void FixedCamera(object oPC, float fFrameRate = 30.0)
  36. {
  37. string sCamera = GetLocalString(oPC,"sFixedCamera"); // Gets the camera position to use
  38. if (sCamera == "") // Camera tracking is turned off, stop script and don't recheck
  39. { return; }
  40.  
  41. float fHeight = GetLocalFloat(oPC,"fFixedCamera"); // Gets the camera height to use
  42. if (fHeight == 0.0) { fHeight = 10.0; } // Defaults camera height to 10.0 if none has been set yet
  43.  
  44. object oCamera = GetObjectByTag(sCamera);
  45. float fDelay = 1.0 / fFrameRate;
  46. float fRange = GetHorizontalDistanceBetween(oPC,oCamera);
  47.  
  48. float fAngle = GetDirection(oPC,oCamera); // Works out angle between camera and player
  49. float fPitch = atan(fRange/fHeight); // Works out vertical tilt
  50. float fDistance = sqrt(pow(fHeight,2.0) + pow(fRange,2.0)); // Works out camera distance from player
  51. if (fDistance > 30.0) { fDistance = 30.0; } // Sets distance to 30.0 if player is too far away
  52. if (fDistance < 5.0) { fDistance = 5.0; } // Sets distance to 5.0 if player is too close
  53.  
  54. AssignCommand(oPC,SetCameraFacing(fAngle,fDistance,fPitch, CAMERA_TRANSITION_TYPE_VERY_FAST));
  55. DelayCommand(fDelay,FixedCamera(oPC,fFrameRate));
  56. }
  57.  
  58. //void main(){}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement