-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathTimeFreeze.lua
More file actions
638 lines (586 loc) · 24.7 KB
/
Copy pathTimeFreeze.lua
File metadata and controls
638 lines (586 loc) · 24.7 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
-- Register the behaviour
behaviour("TimeFreeze")
local savedVelocity = {}
function TimeFreeze:Start()
GameEvents.onActorSpawn.AddListener(self,"onActorSpawn")
self.savedAmmoWeapons = {}
self.savedLineRenderer = {}
self.isFrozen = false
self.isDrawing = false
self.currentLineRenderer = nil
self.currentLineRendererEnd = nil
self.currentisActor = false
self.selectedMove = nil
self.projectilesInLevel = {}
self.projectileParticleSystemActive = {}
self.maxProjectileText = self.targets.maxProjectileReached.GetComponent(Text)
self.spawnedHitboxInstance = {}
self.hitBox = self.targets.hitbox
self.projectileLimit = 0
self.projectileLimitReached = false
self.isMovingBot = false
self.PlayerFpParent = GameObject.Find("Shoulder Parent")
if(self.PlayerFpParent == nil) then
print("Shoulder Parent is nil!")
end
self.maxProjectiles = self.script.mutator.GetConfigurationRange("maxProjectiles")
self.maxProjectilesAT = self.maxProjectiles / 2
self.isMovingProjectile = false
self.cooldownStart = 0
self.infiniteAmmoWhenFrozen = true
self.applyForceAtPosition = self.script.mutator.GetConfigurationBool("forceAtPosition")
self.currentActor = nil
self.currentRigidbody = nil
self.currentLineRendererStart = nil
self.currentPosByRaycastPoint = false
self.speed = self.script.mutator.GetConfigurationRange("speed")
self.canvas = self.targets.canvas
self.canvas.gameObject.SetActive(false)
self.image = self.targets.image
self.isHidden = false
self.forceMuliplier = self.script.mutator.GetConfigurationRange("forceMultiplier")
self.autoKillSelectedBots = self.script.mutator.GetConfigurationBool("automaticallyKillBots")
end
function TimeFreeze:onActorSpawn(actor)
if(not actor.isBot) then
for i,y in ipairs(actor.weaponSlots) do
table.insert(self.savedAmmoWeapons, {y,y.ammo})
end
end
end
function TimeFreeze:CreateLineRendererForObject(rigidbody)
local lineRenderer = GameObject.Instantiate(self.targets.lineRenderer)
table.insert(self.savedLineRenderer, {lineRenderer.GetComponent(LineRenderer),rigidbody})
print("Added lineRenderer to list")
self.isDrawing = true
self.currentRigidbody = rigidbody
self.currentLineRenderer = lineRenderer.GetComponent(LineRenderer)
return lineRenderer.GetComponent(LineRenderer)
end
function TimeFreeze:SpawnInvHitBox(projectile)
if(projectile ~= nil) then -- Problem
local hitBox = GameObject.Instantiate(self.hitBox)
hitBox.gameObject.name = hitBox.gameObject.name .. " MoveProj"
hitBox.gameObject.transform.position = projectile.transform.position
-- hitBox.gameObject.layer = -14682625
--print("New Weapon collider name : " .. weaponColliderGameObject.gameObject.name)
projectile.transform.parent = hitBox.transform
hitBox.transform.localScale = Vector3(0.7,0.7,0.7)
hitBox.transform.rotation = projectile.transform.rotation
table.insert(self.spawnedHitboxInstance, hitBox)
end
end
function TimeFreeze:ClearSpawnedHitboxInstanceList()
for k,a in pairs (self.spawnedHitboxInstance) do
if(a ~= nil) then
if(a.transform.GetChild(0) ~= nil) then
a.transform.GetChild(0).transform.parent = nil
GameObject.Destroy(a)
end
GameObject.Destroy(a)
end
end
for k in pairs (self.spawnedHitboxInstance) do
self.spawnedHitboxInstance [k] = nil
end
end
function TimeFreeze:SetLineRendererStart(lineRenderer,startP)
lineRenderer.SetPosition(0,startP)
end
function TimeFreeze:GetAllProjectiles()
for i,y in ipairs(GameObject.FindObjectsOfType(Projectile)) do -- Yikes
if y.gameObject.activeSelf == true and y.velocity ~= Vector3.zero and y.gameObject.GetComponent(Light) ~= nil then
table.insert(self.projectilesInLevel, y)
else if y.gameObject.activeSelf == true and y.velocity ~= Vector3.zero and y.isTravellingTowardsPlayer then
table.insert(self.projectilesInLevel, y)
end
end
end
end
function TimeFreeze:ClearProjectileList()
for k in pairs (self.projectilesInLevel) do
self.projectilesInLevel [k] = nil
end
for a in pairs(self.spawnedHitboxInstance) do
self.spawnedHitboxInstance [a] = nil
end
end
function TimeFreeze:SetLineRendererEnd(lineRenderer,endP,raycastR)
self.currentLineRendererStart = lineRenderer.GetPosition(0)
if(raycastR) then
self.currentLineRendererEnd = endP + Vector3(0,1,0)
self.currentPosByRaycastPoint = true
else
self.currentLineRendererEnd = endP
self.currentPosByRaycastPoint = false
end
lineRenderer.SetPosition(1,endP)
end
function TimeFreeze:CalculateTrajectory( TargetDistance, velocity)
local n = (-Physics.gravity.y * TargetDistance)
local b = velocity * velocity
local CalculatedAngle = 0.5 * ((Mathf.Asin (n / b)) * Mathf.Rad2Deg);
if(CalculatedAngle ~= CalculatedAngle) then
return 0
end
return CalculatedAngle
end
function TimeFreeze:SetLineRendererFinal(lineRenderer,endP)
lineRenderer.positionCount = 2
if(self.currentPosByRaycastPoint) then
lineRenderer.SetPosition(1,endP - Vector3(0,1,0))
else
lineRenderer.SetPosition(1,endP)
end
lineRenderer.material.color = Color.blue
lineRenderer.material.color = Color.blue
lineRenderer.endWidth = 0.2
print("LineRenderer finished")
self.currentLineRenderer = nil
self.isDrawing = false
-- self.currentRigidbody.AddForce(Vector3(0,50,0),ForceMode.Impulse)
local dir
if(self.currentisActor) then
-- print("Actor detected")
dir = (self.currentLineRendererEnd) - self.currentLineRendererStart
local force = Vector3.Scale((dir.normalized * dir.magnitude * 54 * self.forceMuliplier),Vector3(1,1,1))
local calcTraj = self:CalculateTrajectory(dir.magnitude,force.magnitude)
local newF
if calcTraj ~= 0 then
local trajectoryHeight = Mathf.Tan(calcTraj * Mathf.Deg2Rad) * dir.magnitude
print(trajectoryHeight)
newF = Vector3(force.x,force.y + trajectoryHeight,force.z)
end
-- if(self.currentActor.isSeated) then
-- self.currentActor.ExitVehicle()
-- end
self.currentActor.KnockOver(newF)
if(self.autoKillSelectedBots) then
self.currentActor.Damage(self.currentActor.health)
end
return
end
local dir = self.currentLineRendererEnd - self.currentLineRendererStart
--print(tostring(dir.magnitude))
local useMass
if(self.currentRigidbody.mass == 0) then
useMass = 1
else
useMass = self.currentRigidbody.mass
end
local vehicle
local mtpl = 1
if(self.currentRigidbody.transform.root.gameObject.GetComponent(Vehicle) ~= nil) then
-- print("Got vehicle")
vehicle = self.currentRigidbody.transform.root.gameObject.GetComponent(Vehicle)
if(vehicle.isAircraft) then
mtpl = 1
dir = ((self.currentLineRendererEnd - Vector3(0,1,0))) - self.currentLineRendererStart
else
mtpl = 1.5
end
end
local force = Vector3.Scale((dir.normalized * dir.magnitude * (2 * self.forceMuliplier) * (useMass / 2) ),Vector3(1,mtpl,1))
local calcTraj = self:CalculateTrajectory(dir.magnitude,force.magnitude)
local newF
if calcTraj ~= 0 then
local trajectoryHeight = Mathf.Tan(calcTraj * Mathf.Deg2Rad) * dir.magnitude
newF = Vector3(force.x,force.y + trajectoryHeight,force.z)
end
if(self.applyForceAtPosition) then
self.currentRigidbody.AddForceAtPosition(newF,self.currentLineRendererStart,ForceMode.Impulse)
else
self.currentRigidbody.AddForce(newF,ForceMode.Impulse)
end
end
function TimeFreeze:RemoveCurrentLineRenderer()
GameObject.Destroy(self.currentLineRenderer)
table.remove(self.savedLineRenderer,self:tablefind(self.savedLineRenderer,self.currentLineRenderer))
end
function TimeFreeze:AddForceByLineRenderer(lineRenderer,rigidbody)
local dir = lineRenderer.GetPosition(1) - lineRenderer.GetPosition(0)
print(tostring(dir.magnitude))
local force = Vector3.Scale((dir.normalized * dir.magnitude * 5 * rigidbody.mass),Vector3(1,1.3,1))
rigidbody.AddForceAtPosition(force,lineRenderer.GetPosition(0),ForceMode.Impulse)
print("Applying " .. tostring(force) .. " to " .. rigidbody.transform.name)
end
function TimeFreeze:tablefind(tab,el)
for index, value in pairs(tab) do
if value[1] == el then
return index
end
end
end
function TimeFreeze:Update()
if self.PlayerFpParent == nil then
self.PlayerFpParent = GameObject.Find("Shoulder Parent")
return
end
if(Input.GetKeyDown(KeyCode.End) and self.isFrozen) then
self.isHidden = not self.isHidden
if(self.isHidden) then
self.canvas.gameObject.SetActive(false)
else
self.canvas.gameObject.SetActive(true)
end
end
if Input.GetKeyDown(KeyCode.H) and not Player.actor.isSeated then
self.isFrozen = not self.isFrozen
if(self.isFrozen) then
for i,y in ipairs(Player.actor.weaponSlots) do
y.LockWeapon()
end
-- self:GetAllProjectiles()
-- for z,p in ipairs(self.projectilesInLevel) do
-- self:SpawnInvHitBox(p)
-- end
self.canvas.gameObject.SetActive(true)
self.isHidden = false
self.maxProjectileText.color = Color(1,0,0,0)
PlayerCamera.ResetRecoil()
self.PlayerFpParent.transform.localEulerAngles = Vector3(0,0,0)
self.targets.forceLineInfoTextAnimator.SetBool("fadeOut",true)
Time.timeScale = 0.000001
else
Time.timeScale = 1
PlayerCamera.ResetRecoil()
if(self.isDrawing) then
self:RemoveCurrentLineRenderer()
--print("Player was still drawing line")
self.isDrawing = false
self.currentLineRenderer = nil
end
-- self:ClearSpawnedHitboxInstanceList()
-- self:ClearProjectileList()
for i,y in ipairs(Player.actor.weaponSlots) do
y.UnlockWeapon()
end
self.isMovingBot = false
self.selectedMove = nil
self.maxProjectileText.color = Color(1,0,0,0)
self.isMovingProjectile = false
-- Apply Force
-- Clear self.savedLineRenderer
-- for i,y in ipairs(self.savedLineRenderer) do
-- self:AddForceByLineRenderer(y[1],y[2])
-- end
for i,y in ipairs(self.savedLineRenderer) do
GameObject.Destroy(y[1])
end
for k in pairs (self.savedLineRenderer) do
self.savedLineRenderer [k] = nil
end
-- print("Cleared list and destoryed objects")
self.targets.forceLineInfoTextAnimator.SetBool("fadeOut",false)
self.projectileLimitReached = false
self.projectileLimit = 0
self.targets.forceLineInfoText.GetComponent(Text).color = Color(1,1,1,1)
self.isHidden = true
self.canvas.gameObject.SetActive(false)
end
end
if(self.isFrozen and PlayerCamera.activeCamera.main ~= nil) then
if(Player.actor.isSeated) then
Player.actor.ExitVehicle()
end
PlayerCamera.ResetRecoil()
-- if(not Player.actorIsGrounded) then
-- local ray = Ray(PlayerCamera.activeCamera.main.transform.position, Vector3.down)
-- local raycast = Physics.Raycast(ray,1000,RaycastTarget.ProjectileHit)
-- if(raycast ~= nil) then
-- Player.MoveActor((raycast.point - Player.actor.transform.parent.position) * -Time.unscaledDeltaTime * 8)
-- end
-- end
if(Input.GetKey(KeyCode.W)) then
Player.MoveActor(PlayerCamera.activeCamera.main.transform.forward / (15 / self.speed))
end
if(Input.GetKey(KeyCode.A)) then
Player.MoveActor(-PlayerCamera.activeCamera.main.transform.right / (17 / self.speed))
end
if(Input.GetKey(KeyCode.S)) then
Player.MoveActor(-PlayerCamera.activeCamera.main.transform.forward / (16 / self.speed))
end
if(Input.GetKey(KeyCode.D)) then
Player.MoveActor(PlayerCamera.activeCamera.main.transform.right / (17 / self.speed))
end
if(Input.GetKey(KeyCode.LeftControl)) then
Player.MoveActor(-PlayerCamera.activeCamera.main.transform.up / (17 / self.speed))
end
if(Input.GetKey(KeyCode.Space)) then
Player.MoveActor(PlayerCamera.activeCamera.main.transform.up / (17 / self.speed))
end
if(Input.GetKeyBindButton(KeyBinds.Sprint) and Input.GetKey(KeyCode.LeftControl) ) then
Player.MoveActor(-PlayerCamera.activeCamera.main.transform.up / (5 / self.speed))
end
if(Input.GetKeyBindButton(KeyBinds.Sprint) and Input.GetKey(KeyCode.Space) ) then
Player.MoveActor(PlayerCamera.activeCamera.main.transform.up / (5 / self.speed))
end
if(Input.GetKeyBindButton(KeyBinds.Sprint) and Input.GetKey(KeyCode.W) ) then
Player.MoveActor(PlayerCamera.activeCamera.main.transform.forward / (4 / self.speed))
end
if(Input.GetKeyBindButton(KeyBinds.Sprint) and Input.GetKey(KeyCode.S) ) then
Player.MoveActor(-PlayerCamera.activeCamera.main.transform.forward / (4 / self.speed))
end
if(Input.GetKeyBindButton(KeyBinds.Sprint) and Input.GetKey(KeyCode.A) ) then
Player.MoveActor(-PlayerCamera.activeCamera.main.transform.right / (5 / self.speed))
end
if(Input.GetKeyBindButton(KeyBinds.Sprint) and Input.GetKey(KeyCode.D) ) then
Player.MoveActor(PlayerCamera.activeCamera.main.transform.right / (5 / self.speed))
end
if Input.GetKeyDown(KeyCode.T) then
--Overlay.ShowMessage("<color=#34abeb>Switched</color>")
local ray = Ray(PlayerCamera.activeCamera.main.transform.position + PlayerCamera.activeCamera.main.transform.forward * 1, PlayerCamera.activeCamera.main.transform.forward)
local raycast = Physics.Raycast(ray,1100, RaycastTarget.ProjectileHit)
if raycast ~= nil then
Player.actor.transform.parent.position = raycast.point - PlayerCamera.activeCamera.main.transform.forward
end
end
if(Player.actor.activeWeapon ~= nil) then
if(Input.GetKeyBindButtonDown(KeyBinds.Reload)) then
if(Player.actor.activeWeapon.spareAmmo ~= 0) then
for i,y in ipairs(self.savedAmmoWeapons) do
if(y[1] == Player.actor.activeWeapon) then
local ammoNeeded = y[2] - Player.actor.activeWeapon.ammo
Player.actor.activeWeapon.ammo = y[2]
if(not self.infiniteAmmoWhenFrozen) then
Player.actor.activeWeapon.spareAmmo = Player.actor.activeWeapon.spareAmmo - ammoNeeded
end
end
end
end
end
if(Input.GetKeyBindButtonDown(KeyBinds.Fire) and not GameManager.isPaused) then
if(Player.actor.activeWeapon.ammo ~= 0 and not Player.actor.activeWeapon.isReloading and not Player.actor.activeWeapon.isOverheating and not Player.actor.activeWeapon.isEmpty and not self.projectileLimitReached ) then
if(self.projectileLimit > self.maxProjectiles) then
self.projectileLimitReached = true
self.maxProjectileText.color = Color(1,0,0,1)
return
else if self.projectileLimit > self.maxProjectilesAT and Player.actor.activeWeapon.weaponEntry.type == LoadoutType.AntiArmor then
self.projectileLimitReached = true
self.maxProjectileText.color = Color(1,0,0,1)
return
end
end
self.projectileLimit = self.projectileLimit + 1
Player.actor.activeWeapon.Shoot(true)
end
end
end
if(Input.GetKeyBindButton(KeyBinds.Aim) and not GameManager.isPaused) then
if(Player.actor.activeWeapon.spareAmmo ~= 0) then
if(Player.actor.activeWeapon.ammo == 0) then
for i,y in ipairs(self.savedAmmoWeapons) do
if(y[1] == Player.actor.activeWeapon) then
local ammoNeeded = y[2] - Player.actor.activeWeapon.ammo
Player.actor.activeWeapon.ammo = y[2]
if(not self.infiniteAmmoWhenFrozen) then
Player.actor.activeWeapon.spareAmmo = Player.actor.activeWeapon.spareAmmo - ammoNeeded
end
end
end
end
end
if(Player.actor.activeWeapon.ammo ~= 0 and not Player.actor.activeWeapon.isReloading and not Player.actor.activeWeapon.isOverheating and not Player.actor.activeWeapon.isEmpty and not self.projectileLimitReached ) then
if(self.projectileLimit > self.maxProjectiles) then
self.projectileLimitReached = true
self.maxProjectileText.color = Color(1,0,0,1)
return
else if self.projectileLimit > self.maxProjectilesAT and Player.actor.activeWeapon.weaponEntry.type == LoadoutType.AntiArmor then
self.projectileLimitReached = true
self.maxProjectileText.color = Color(1,0,0,1)
return
end
end
self.projectileLimit = self.projectileLimit + 1
Player.actor.activeWeapon.Shoot(true)
end
end
if(self.isDrawing and self.currentLineRenderer ~= nil) then
local ray = Ray(PlayerCamera.activeCamera.main.transform.position + PlayerCamera.activeCamera.main.transform.forward * 1, PlayerCamera.activeCamera.main.transform.forward)
local raycast = Physics.Raycast(ray,30,RaycastTarget.ProjectileHit)
if(raycast ~= nil) then
--self:SetLineRendererEnd(self.currentLineRenderer,PlayerCamera.activeCamera.main.transform.position + PlayerCamera.activeCamera.main.transform.forward * 4.5)
self:SetLineRendererEnd(self.currentLineRenderer,raycast.point,true)
else
self:SetLineRendererEnd(self.currentLineRenderer,PlayerCamera.activeCamera.main.transform.position + PlayerCamera.activeCamera.main.transform.forward * 4.3,false )
end
end
if(self.isMovingBot) then
if(self.isMovingProjectile) then
--Handle pos set
local playerPos = PlayerCamera.activeCamera.main.transform.position + PlayerCamera.activeCamera.main.transform.forward * 5.5
local directionBetweenPlayerAndPoint = playerPos - PlayerCamera.activeCamera.main.transform.position
local rot = Quaternion.LookRotation(directionBetweenPlayerAndPoint)
self.selectedMove.transform.rotation = rot
self.selectedMove.transform.localPosition = playerPos
else
local playerPos = PlayerCamera.activeCamera.main.transform.position + PlayerCamera.activeCamera.main.transform.forward * 7.5
local directionBetweenPlayerAndPoint = PlayerCamera.activeCamera.main.transform.position - playerPos
self.selectedMove.transform.rotation = Quaternion.LookRotation(directionBetweenPlayerAndPoint)
self.selectedMove.transform.position = playerPos
end
end
-- if(Input.GetKeyDown(KeyCode.X)) then
-- -- if(self.isMovingBot) then
-- -- -- Place proj
-- -- if(self.isMovingProjectile) then
-- -- local previoursMagn = self.selectedMove.GetComponentInChildren(Projectile).velocity.magnitude
-- -- local playerPos = PlayerCamera.activeCamera.main.transform.position + PlayerCamera.activeCamera.main.transform.forward * 7.5
-- -- local directionBetweenPlayerAndPoint = playerPos - PlayerCamera.activeCamera.main.transform.position
-- -- for i,y in ipairs(self.projectileParticleSystemActive) do
-- -- y.Play(true)
-- -- end
-- -- for k in pairs (self.projectileParticleSystemActive) do
-- -- self.projectileParticleSystemActive [k] = nil
-- -- end
-- -- self.selectedMove.GetComponentInChildren(Projectile).velocity = directionBetweenPlayerAndPoint.normalized * previoursMagn
-- -- end
-- -- self.isMovingBot = false
-- -- self.isMovingProjectile = false
-- -- self.selectedMove = nil
-- -- print("Set to false")
-- -- return
-- -- end
-- local ray = Ray(PlayerCamera.activeCamera.main.transform.position + PlayerCamera.activeCamera.main.transform.forward * 1, PlayerCamera.activeCamera.main.transform.forward)
-- local raycast = Physics.Raycast(ray,90,RaycastTarget.ProjectileHit)
-- if(raycast ~= nil) then
-- if(self.isMovingBot) then
-- -- if string.find(raycast.transform.gameObject.name,"MoveProj") then
-- -- print("Set projectile")
-- self.selectedMove = raycast.transform.gameObject
-- -- local ps = self.selectedMove.gameObject.GetComponentsInChildren(ParticleSystem)
-- -- for i,y in ipairs(ps) do
-- -- if(y.isEmitting or y.isPlaying) then
-- -- table.insert(self.projectileParticleSystemActive, y)
-- -- y.Clear(true)
-- -- y.Stop(true)
-- -- end
-- -- end
-- self.isMovingBot = true
-- self.isMovingProjectile = true
-- return
-- end
-- if(raycast.transform.root.gameObject.GetComponent(Actor) ~= nil) then
-- local actor = raycast.transform.root.gameObject.GetComponent(Actor)
-- self.selectedMove = actor.transform.gameObject
-- self.isMovingBot = true
-- print("Set actor")
-- else if(raycast.transform.gameObject.GetComponent(Rigidbody) ~= nil) then
-- self.selectedMove = raycast.transform.gameObject
-- self.isMovingBot = true
-- print("Set rigidbody")
-- end
-- end
-- end
-- end
if(self.isMovingBot) then
if(self.isMovingProjectile) then
--Handle pos set
local playerPos = PlayerCamera.activeCamera.main.transform.position + PlayerCamera.activeCamera.main.transform.forward * 5.5
local directionBetweenPlayerAndPoint = playerPos - PlayerCamera.activeCamera.main.transform.position
local rot = Quaternion.LookRotation(directionBetweenPlayerAndPoint)
self.selectedMove.transform.rotation = rot
self.selectedMove.transform.localPosition = playerPos
else
local playerPos = PlayerCamera.activeCamera.main.transform.position + PlayerCamera.activeCamera.main.transform.forward * 7.5
local directionBetweenPlayerAndPoint = PlayerCamera.activeCamera.main.transform.position - playerPos
self.selectedMove.transform.rotation = Quaternion.LookRotation(directionBetweenPlayerAndPoint)
self.selectedMove.transform.position = playerPos
end
end
if(Input.GetKeyDown(KeyCode.X)) then
if(self.isMovingBot) then
-- Place proj
-- if(self.isMovingProjectile) then
-- local previoursMagn = self.selectedMove.GetComponentInChildren(Projectile).velocity.magnitude
-- local playerPos = PlayerCamera.activeCamera.main.transform.position + PlayerCamera.activeCamera.main.transform.forward * 7.5
-- local directionBetweenPlayerAndPoint = playerPos - PlayerCamera.activeCamera.main.transform.position
-- self.selectedMove.GetComponentInChildren(Projectile).velocity = directionBetweenPlayerAndPoint.normalized * previoursMagn
-- end
self.isMovingBot = false
self.selectedMove = nil
self.isMovingProjectile = false
-- print("Set to false")
return
end
local ray = Ray(PlayerCamera.activeCamera.main.transform.position + PlayerCamera.activeCamera.main.transform.forward * 1, PlayerCamera.activeCamera.main.transform.forward)
local raycast = Physics.Raycast(ray,90,RaycastTarget.ProjectileHit)
if(raycast ~= nil) then
-- if string.find(raycast.transform.gameObject.name,"MoveProj") then
-- print("Set projectile")
-- self.selectedMove = raycast.transform.gameObject
-- self.isMovingBot = true
-- self.isMovingProjectile = true
-- return
-- end
if(raycast.transform.root.gameObject.GetComponent(Actor) ~= nil) then
local actor = raycast.transform.root.gameObject.GetComponent(Actor)
self.selectedMove = actor.transform.gameObject
self.isMovingBot = true
-- print("Set actor")
else if(raycast.transform.gameObject.GetComponent(Rigidbody) ~= nil) then
self.selectedMove = raycast.transform.gameObject
self.isMovingBot = true
-- print("Set rigidbody")
end
end
end
end
if(Input.GetKeyDown(KeyCode.Y)) then
if(self.isDrawing) then
self:SetLineRendererFinal(self.currentLineRenderer,self.currentLineRendererEnd)
return
end
local ray = Ray(PlayerCamera.activeCamera.main.transform.position + PlayerCamera.activeCamera.main.transform.forward * 1, PlayerCamera.activeCamera.main.transform.forward)
local raycast = Physics.Raycast(ray,90,RaycastTarget.ProjectileHit)
if(raycast ~= nil) then
if(raycast.transform.root.gameObject.GetComponent(Vehicle) ~= nil and raycast.transform.gameObject.GetComponentInParent(Actor) ~= nil ) then
if(raycast.transform.root.gameObject.GetComponent(Vehicle).transform.gameObject.GetComponentInChildren(Actor) ~= nil ) then
-- print("Actor is on vehicle")
local actors = raycast.transform.root.gameObject.GetComponent(Vehicle).transform.gameObject.GetComponentsInChildren(Actor)
for i,y in ipairs(actors) do
-- print("if(" .. tostring(y.name) .. " == " .. tostring(raycast.transform.gameObject.GetComponentInParent(Actor).name) .. ") then")
if(y.name == raycast.transform.gameObject.GetComponentInParent(Actor).name) then
-- print("Got actor " .. y.name .. " that was on the vehicle")
self.currentisActor = true
self.currentActor = y
end
end
if(self.currentisActor == true) then
local lineRendererRaycast = self:CreateLineRendererForObject(self.currentActor.gameObject.GetComponent(Rigidbody))
self:SetLineRendererStart(lineRendererRaycast,raycast.point)
self.isDrawing = true
else
-- print("No actors on vehicle")
end
return
else
self.currentisActor = false
end
end
if( raycast.transform.root.gameObject.GetComponent(Actor) ~= nil) then
local actor = raycast.transform.root.gameObject.GetComponent(Actor)
-- print("Actor selected")
self.currentisActor = true
self.currentActor = actor
if(self.currentActor.isSeated) then
self.currentActor.ExitVehicle()
end
local lineRendererRaycast = self:CreateLineRendererForObject(actor.gameObject.GetComponent(Rigidbody))
self:SetLineRendererStart(lineRendererRaycast,raycast.point)
self.isDrawing = true
return
else
self.currentisActor = false
end
if(raycast.transform.gameObject.GetComponent(Rigidbody) ~= nil) and not self.currentisActor then
local lineRendererRaycast = self:CreateLineRendererForObject(raycast.transform.gameObject.GetComponent(Rigidbody) )
self:SetLineRendererStart(lineRendererRaycast,raycast.point)
self.isDrawing = true
else
-- print(raycast.transform.gameObject.name .. " doesn't have a rigidbody")
end
end
end
end
end