dayzspectator.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. class DayZSpectator : Camera
  2. {
  3. private float m_SpeedMultiplier = 1.0;
  4. private float m_SendUpdateAcc = 0.0;
  5. void DayZSpectator()
  6. {
  7. SetEventMask(EntityEvent.FRAME);
  8. }
  9. override void EOnFrame(IEntity other, float timeSlice)
  10. {
  11. if (GetUApi().GetInputByID(UACarShiftGearUp).LocalPress())
  12. m_SpeedMultiplier = m_SpeedMultiplier + 2;
  13. if (GetUApi().GetInputByID(UACarShiftGearDown).LocalPress())
  14. m_SpeedMultiplier = m_SpeedMultiplier - 2;
  15. float speed = 5.0 * m_SpeedMultiplier;
  16. if (GetUApi().GetInputByID(UATurbo).LocalValue())
  17. speed *= 2;
  18. float forward = GetUApi().GetInputByID(UAMoveForward).LocalValue() - GetUApi().GetInputByID(UAMoveBack).LocalValue();
  19. float strafe = GetUApi().GetInputByID(UAMoveRight).LocalValue() - GetUApi().GetInputByID(UAMoveLeft).LocalValue();
  20. vector direction = GetDirection();
  21. vector directionAside = vector.Up * direction;
  22. vector oldPos = GetPosition();
  23. vector forwardChange = forward * timeSlice * direction * speed;
  24. vector strafeChange = strafe * timeSlice * directionAside * speed;
  25. vector newPos = oldPos + forwardChange + strafeChange;
  26. float yMin = GetGame().SurfaceRoadY(newPos[0], newPos[2]);
  27. if (newPos[1] < yMin)
  28. newPos[1] = yMin;
  29. SetPosition(newPos);
  30. float yawDiff = GetUApi().GetInputByID(UAAimLeft).LocalValue() - GetUApi().GetInputByID(UAAimRight).LocalValue();
  31. float pitchDiff = GetUApi().GetInputByID(UAAimDown).LocalValue() - GetUApi().GetInputByID(UAAimUp).LocalValue();
  32. vector oldOrient = GetOrientation();
  33. vector newOrient = oldOrient;
  34. newOrient[0] = newOrient[0] - Math.RAD2DEG * yawDiff * timeSlice;
  35. newOrient[1] = newOrient[1] - Math.RAD2DEG * pitchDiff * timeSlice;
  36. if (newOrient[1] < -89)
  37. newOrient[1] = -89;
  38. if (newOrient[1] > 89)
  39. newOrient[1] = 89;
  40. SetOrientation(newOrient);
  41. if (m_SendUpdateAcc > 0.5)
  42. {
  43. GetGame().UpdateSpectatorPosition(newPos);
  44. m_SendUpdateAcc = 0;
  45. }
  46. m_SendUpdateAcc = m_SendUpdateAcc + timeSlice;
  47. }
  48. };