Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
raycaster.c
Go to the documentation of this file.
1 // Item for raycast debugging. It's also fun to play around with at night.
2 
3 class Raycaster extends ItemBase
4 {
5  protected ref Timer m_Timer;
6 
7  override void OnWorkStart()
8  {
9  if ( !GetGame().IsServer() || !GetGame().IsMultiplayer() ) // Client side
10  {
11  StartPeriodicMeasurement();
12  }
13  }
14 
15  void StartPeriodicMeasurement()
16  {
17  if( !m_Timer )
18  {
19  m_Timer = new Timer;
20  }
21 
22  m_Timer.Run( 0.01, this, "PrepareMeasurement", null, true );
23  }
24 
25  void PrepareMeasurement()
26  {
27  DoMeasurement();
28  DoMeasurement();
29  }
30 
31  void DoMeasurement()
32  {
33  float dispersion = 80;
34 
35  vector from = GetPosition() + ( GetMemoryPointPos("beamStart") + ((GetOrientation()+Vector(90,0,0)).AnglesToVector()*0.3) );
36  vector ori = GetOrientation() + Vector(90,0,0) + Vector(dispersion/2 - Math.RandomFloat(0, dispersion) , dispersion/2 - Math.RandomFloat(0, dispersion) , dispersion/2 - Math.RandomFloat(0, dispersion) );
37  vector to = from + (ori.AnglesToVector() )* 30;
38  vector contact_pos;
39  vector contact_dir;
40  int contactComponent;
41 
42  bool is_collision = DayZPhysics.RaycastRV( from, to, contact_pos, contact_dir, contactComponent, NULL , NULL, GetHierarchyRootPlayer(), false, false, ObjIntersectIFire);
43 
44  if (is_collision)
45  {
46  vector hit_normal = contact_dir.VectorToAngles();
47  hit_normal[1] = hit_normal[1] + 90;
48 
49  // Generate result
50  Particle p = ParticleManager.GetInstance().PlayInWorld(ParticleList.DEBUG_DOT, contact_pos);
51  p.SetOrientation(hit_normal);
52  }
53  }
54 
55  void StopPeriodicMeasurement()
56  {
57  if( m_Timer )
58  {
59  m_Timer.Stop();
60  }
61  }
62 
63  override void OnWorkStop()
64  {
65  if ( !GetGame().IsServer() || !GetGame().IsMultiplayer() ) // Client side
66  {
67  StopPeriodicMeasurement();
68  }
69  }
70 
71  override void SetActions()
72  {
73  super.SetActions();
74 
77  }
78 }
ItemBase
Definition: inventoryitem.c:730
GetGame
proto native CGame GetGame()
Particle
Legacy way of using particles in the game.
Definition: particle.c:6
m_Timer
ref Timer m_Timer
Definition: dayzgame.c:690
ActionTurnOnWhileInHands
Definition: actionturnonwhileinhands.c:1
OnWorkStop
override void OnWorkStop()
Definition: m18smokegrenade_colorbase.c:2
GetPosition
class JsonUndergroundAreaTriggerData GetPosition
Definition: undergroundarealoader.c:9
ParticleList
Definition: particlelist.c:11
vector
Definition: enconvert.c:105
AddAction
void AddAction(typename actionName)
Definition: advancedcommunication.c:86
SetActions
void SetActions()
Definition: advancedcommunication.c:79
ActionTurnOffWhileInHands
Definition: actionturnoffwhileinhands.c:1
DayZPhysics
Definition: dayzphysics.c:123
Timer
Definition: dayzplayerimplement.c:62
Math
Definition: enmath.c:6
ParticleManager
void ParticleManager(ParticleManagerSettings settings)
Constructor (ctor)
Definition: particlemanager.c:84
Vector
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
OnWorkStart
override void OnWorkStart()
Definition: smokegrenadebase.c:175
GetOrientation
vector GetOrientation()
Definition: areadamagemanager.c:306