1 [
EntityEditorProps(
category:
"GameScripted/Shapes", description:
"Procedural box", color:
"255 0 0 255", style:
"box", dynamicBox:
true)]
11 [
Attribute(
"10", UIWidgets.Slider,
"",
"0 100 0.1")]
12 private float m_fDefaultTimeBetweenPoints;
14 private BaseWorld m_World;
15 private IEntitySource m_Source;
17 private ref array<vector> m_aPathPoints = {};
18 private ref array<float> m_aPathSpeedValues = {};
20 private vector m_vCurrentPathPoint;
21 private vector m_vNextPathPoint;
22 private vector m_targetWorldPosition;
24 private int m_iCurrentPathPointIndex;
25 private int m_iNextPathPointIndex = m_iCurrentPathPointIndex+1;
29 override protected void EOnInit(IEntity owner)
35 PolylineShapeEntity polyline = PolylineShapeEntity.Cast(
GetChildren());
36 GetPathFromPolyline(polyline, m_aPathPoints);
39 IEntitySource pnt =
m_Source.GetChild(0);
40 BaseContainerList points = pnt.GetObjectArray(
"Points");
44 for (
int i = 0; i < points.Count(); ++i)
46 BaseContainer point = points.Get(i);
47 BaseContainerList data_array = point.GetObjectArray(
"Data");
49 for (
int j = 0; j < data_array.Count(); ++j)
51 BaseContainer
data = data_array.Get(j);
52 bool hasPointData =
false;
53 if (
data.GetClassName() ==
"SCR_DummyTargetEntity")
56 data.Get(
"m_fTimeToTravel", travel_time);
57 m_aPathSpeedValues.Insert(travel_time);
63 m_vCurrentPathPoint = m_aPathPoints[m_iCurrentPathPointIndex];
64 m_vNextPathPoint = m_aPathPoints[m_iNextPathPointIndex];
65 owner.SetOrigin(m_vCurrentPathPoint);
69 override protected void EOnFrame(IEntity owner,
float timeSlice)
71 vector target_position = owner.GetOrigin();
73 if (VectorEqualApprox(target_position, m_vNextPathPoint, 1))
75 m_iCurrentPathPointIndex++;
76 if (m_iCurrentPathPointIndex == m_aPathPoints.Count())
77 m_iCurrentPathPointIndex = 0;
79 m_iNextPathPointIndex++;
80 if (m_iNextPathPointIndex == m_aPathPoints.Count())
81 m_iNextPathPointIndex = 0;
83 m_vCurrentPathPoint = m_aPathPoints[m_iCurrentPathPointIndex];
84 m_vNextPathPoint = m_aPathPoints[m_iNextPathPointIndex];
89 float cur_time_to_travel = m_fDefaultTimeBetweenPoints;
90 if (m_aPathSpeedValues.Count() > 0)
92 int id = m_iCurrentPathPointIndex;
93 if (
id >= m_aPathSpeedValues.Count())
95 id = m_aPathSpeedValues.Count()-1;
97 cur_time_to_travel = m_aPathSpeedValues[id];
101 float dist = vector.Distance(m_vCurrentPathPoint, m_vNextPathPoint);
102 float velocity = dist / cur_time_to_travel;
103 float cur_camera_speed = velocity * timeSlice;
105 vector movement_dir = vector.Direction(m_vCurrentPathPoint, m_vNextPathPoint).Normalized();
107 target_position = target_position + movement_dir * cur_camera_speed;
109 this.SetOrigin(target_position);
113 private void GetPathFromPolyline(PolylineShapeEntity polyline, out array <vector> path)
115 vector offset = polyline.GetOrigin();
116 array <vector> temp_path = {};
117 polyline.GetPointsPositions(temp_path);
119 for (
int i = 0; i < temp_path.Count(); ++i)
121 temp_path[i] = temp_path[i] + offset;
126 private bool VectorEqualApprox(vector v1, vector v2,
float epsilon = 1)
128 return (Math.AbsFloat(v1[0] - v2[0]) < epsilon)
129 && (Math.AbsFloat(v1[1] - v2[1]) < epsilon)
130 && (Math.AbsFloat(v1[2] - v2[2]) < epsilon);
136 SetEventMask(EntityEvent.FRAME | EntityEvent.INIT);