Script v1.7.1.0
- AI
- AIDriveStrategy
- AIDriveStrategyBaler
- AIDriveStrategyCollision
- AIDriveStrategyCombine
- AIDriveStrategyConveyor
- AIDriveStrategyStraight
- AITurnStrategy
- AITurnStrategyBulb1
- AITurnStrategyBulb1Revers...
- AITurnStrategyBulb2
- AITurnStrategyBulb2Revers...
- AITurnStrategyBulb3
- AITurnStrategyBulb3Revers...
- AITurnStrategyDefault
- AITurnStrategyDefaultReve...
- AITurnStrategyHalfCircle
- AITurnStrategyHalfCircleR...
- HelperManager
- NPCManager
- Animals
- Contracts
- Debug
- Economy
- Effects
- Events
- Farms
- GUI
- Handtools
- I3d
- Materials
- Misc
- Objects
- Placeables
- Player
- Shop
- Sounds
- Specializations
- Triggers
- Utils
- Vehicles
- Weather
Engine v1.7.1.0
- AI
- Animation
- Camera
- Entity
- Fillplanes
- General
- I3D
- Input
- Lighting
- Math
- Network
- Node
- Overlays
- Particle System
- Physics
- Rendering
- Scenegraph
- Shape
- Sound
- Spline
- String
- Terrain Detail
- Text Rendering
- Tire Track
- XML
- general
Foundation Reference
AIDriveStrategyConveyor
DescriptionClass for a drive strategy for driving forward and backward Copyright (C) GIANTS Software GmbH, Confidential, All Rights Reserved.Parent
AIDriveStrategyFunctions
getDriveData
DescriptionDefinitiongetDriveData()Code
55 | function AIDriveStrategyConveyor:getDriveData(dt, vX, vY, vZ) |
56 | local _, y, z = localToLocal(self.vehicle.wheels[self.vehicle.aiConveyorBelt.backWheelIndex].repr, self.vehicle.components[1].node, 0, 0, 0) |
57 | local worldCX, worldCY, worldCZ = localToWorld(self.vehicle.components[1].node, 0, y, z) |
58 | local distanceMoved = MathUtil.vector2Length(worldCX-self.lastPos[1], worldCZ-self.lastPos[3]) |
59 | |
60 | self.distanceMoved = self.distanceMoved + distanceMoved |
61 | self.lastPos = {worldCX, worldCY, worldCZ} |
62 | |
63 | if self.distanceMoved >= self.distanceToMove then |
64 | if self.fistTimeChange then |
65 | self.distanceToMove = self.distanceToMove * 2 |
66 | self.fistTimeChange = false |
67 | end |
68 | |
69 | self.distanceMoved = 0 |
70 | if self.currentTarget == 1 then |
71 | self.currentTarget = 2 |
72 | else |
73 | self.currentTarget = 1 |
74 | end |
75 | end |
76 | |
77 | local speedFactor = MathUtil.clamp(math.sin(self.distanceMoved/self.distanceToMove*3.14), 0.1, 0.5)*2 |
78 | |
79 | local dir = true |
80 | if self.currentTarget == 2 then |
81 | dir = not dir |
82 | end |
83 | return self.worldTarget[self.currentTarget][1], self.worldTarget[self.currentTarget][3], dir, self.vehicle.aiConveyorBelt.speed*speedFactor, 100 |
84 | end |
new
DescriptionDefinitionnew()Code
11 | function AIDriveStrategyConveyor:new(customMt) |
12 | if customMt == nil then |
13 | customMt = AIDriveStrategyConveyor_mt |
14 | end |
15 | |
16 | local self = AIDriveStrategy:new(customMt) |
17 | |
18 | return self |
19 | end |
setAIVehicle
DescriptionDefinitionsetAIVehicle()Code
23 | function AIDriveStrategyConveyor:setAIVehicle(vehicle) |
24 | AIDriveStrategyConveyor:superClass().setAIVehicle(self, vehicle) |
25 | |
26 | local _, y, z = localToLocal(self.vehicle.wheels[self.vehicle.aiConveyorBelt.backWheelIndex].repr, self.vehicle.components[1].node, 0, 0, 0) |
27 | local x1, y1, z1 = localToWorld(self.vehicle.components[1].node, 0, y, z) |
28 | local x2, y2, z2 = getWorldTranslation(self.vehicle.wheels[self.vehicle.aiConveyorBelt.centerWheelIndex].repr) |
29 | |
30 | local length = MathUtil.vector3Length(x1-x2, y1-y2, z1-z2) |
31 | local width = length * math.sin(math.rad(self.vehicle.aiConveyorBelt.currentAngle/2)) |
32 | local length2 = math.sqrt(math.pow(length, 2)-math.pow(width, 2)) |
33 | |
34 | self.distanceToMove = math.rad(self.vehicle.aiConveyorBelt.currentAngle)*length/2 |
35 | |
36 | self.currentTarget = 1 |
37 | |
38 | self.worldTarget = {} |
39 | self.worldTarget[1] = {localToWorld(self.vehicle.wheels[self.vehicle.aiConveyorBelt.centerWheelIndex].repr, width, 0, -length2)} |
40 | self.worldTarget[2] = {localToWorld(self.vehicle.wheels[self.vehicle.aiConveyorBelt.centerWheelIndex].repr, -width, 0, -length2)} |
41 | |
42 | self.lastPos = {x1, y1, z1} |
43 | |
44 | self.distanceMoved = 0 |
45 | self.fistTimeChange = true |
46 | end |
update
DescriptionDefinitionupdate()Code
50 | function AIDriveStrategyConveyor:update(dt) |
51 | end |