forked from Stephan-S/FS19_AutoDrive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
draw collision debugcube.txt
33 lines (30 loc) · 1.65 KB
/
draw collision debugcube.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
local x,y,z = getWorldTranslation( vehicle.components[1].node );
--create bounding box to check for vehicle
local rx,ry,rz = localDirectionToWorld(vehicle.components[1].node, math.sin(vehicle.rotatedTime),0,math.cos(vehicle.rotatedTime));
local vehicleVector = {x= math.sin(rx) ,z= math.sin(rz)};
local width = vehicle.sizeWidth;
local length = vehicle.sizeLength;
local ortho = { x=-vehicleVector.z, z=vehicleVector.x };
local lookAheadDistance = math.min(vehicle.lastSpeedReal*3600/40, 1) * 10 + 2;
local box = {};
box.center = {};
box.size = {};
box.center[1] = 0;
box.center[2] = 3;
box.center[3] = length;
box.size[1] = width/2;
box.size[2] = 1.5;
box.size[3] = lookAheadDistance/2;
box.x, box.y, box.z = localToWorld(vehicle.components[1].node, box.center[1], box.center[2], box.center[3])
box.zx, box.zy, box.zz = localDirectionToWorld(vehicle.components[1].node, math.sin(vehicle.rotatedTime),0,math.cos(vehicle.rotatedTime))
box.xx, box.xy, box.xz = localDirectionToWorld(vehicle.components[1].node, -math.cos(vehicle.rotatedTime),0,math.sin(vehicle.rotatedTime))
box.ry = math.atan2(box.zx, box.zz)
local boxCenter = { x = x + (((length/2 + (lookAheadDistance/2)) * vehicleVector.x)),
y = y+3,
z = z + (((length/2 + (lookAheadDistance/2)) * vehicleVector.z)) };
local shapes = overlapBox(boxCenter.x,boxCenter.y,boxCenter.z, 0,box.ry,0, box.size[1],box.size[2],box.size[3], "collisionTestCallback", nil, AIVehicleUtil.COLLISION_MASK, true, true, true)
local red = 0;
if shapes > 0 then
red = 1;
end;
DebugUtil.drawOverlapBox(boxCenter.x,boxCenter.y,boxCenter.z, 0,box.ry,0, box.size[1],box.size[2],box.size[3], red, 0, 0);