Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Gives the illusion of the camera being fixed in one place and rotating to face the player as they move
- // oPC the PC you want to apply the camera movement to
- // fFrameRate number of movements per second (governs how smooth the motion is)
- //
- // To setup a fixed camera position, place a waypoint with a unique tag in your area
- // Set the camera's tag as a LocalString "sFixedCamera" on the PC to let them know to use that camera
- // Set a LocalFloat "fFixedCamera" on the PC to set the camera's vertical position
- // Set "sFixedCamera" to "" to end the tracking
- void FixedCamera(object oPC, float fFrameRate = 30.0);
- vector GetVectorAB(object oA, object oB)
- {
- vector vA = GetPosition(oA);
- vector vB = GetPosition(oB);
- vector vDelta = (vA - vB);
- return vDelta;
- }
- float GetHorizontalDistanceBetween(object oA, object oB)
- {
- vector vHorizontal = GetVectorAB(oA,oB);
- float fDistance = sqrt(pow(vHorizontal.x,2.0) + pow(vHorizontal.y,2.0));
- return fDistance;
- }
- float GetDirection(object oTarget, object oPC)
- {
- vector vdTarget = GetVectorAB(oTarget,oPC);
- float fDirection = VectorToAngle(vdTarget);
- return fDirection;
- }
- void FixedCamera(object oPC, float fFrameRate = 30.0)
- {
- string sCamera = GetLocalString(oPC,"sFixedCamera"); // Gets the camera position to use
- if (sCamera == "") // Camera tracking is turned off, stop script and don't recheck
- { return; }
- float fHeight = GetLocalFloat(oPC,"fFixedCamera"); // Gets the camera height to use
- if (fHeight == 0.0) { fHeight = 10.0; } // Defaults camera height to 10.0 if none has been set yet
- object oCamera = GetObjectByTag(sCamera);
- float fDelay = 1.0 / fFrameRate;
- float fRange = GetHorizontalDistanceBetween(oPC,oCamera);
- float fAngle = GetDirection(oPC,oCamera); // Works out angle between camera and player
- float fPitch = atan(fRange/fHeight); // Works out vertical tilt
- float fDistance = sqrt(pow(fHeight,2.0) + pow(fRange,2.0)); // Works out camera distance from player
- if (fDistance > 30.0) { fDistance = 30.0; } // Sets distance to 30.0 if player is too far away
- if (fDistance < 5.0) { fDistance = 5.0; } // Sets distance to 5.0 if player is too close
- AssignCommand(oPC,SetCameraFacing(fAngle,fDistance,fPitch, CAMERA_TRANSITION_TYPE_VERY_FAST));
- DelayCommand(fDelay,FixedCamera(oPC,fFrameRate));
- }
- //void main(){}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement