-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
af50945
commit 0d6592a
Showing
11 changed files
with
552 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using Unigine; | ||
|
||
#region Math Variables | ||
#if UNIGINE_DOUBLE | ||
using Vec3 = Unigine.dvec3; | ||
#else | ||
using Vec3 = Unigine.vec3; | ||
#endif | ||
#endregion | ||
|
||
[Component(PropertyGuid = "88d6112b0032ace8365867c48dbe1958c29471f7")] | ||
public class Bullet : Component | ||
{ | ||
public float speed = 10.0f; | ||
public int damage = 1; | ||
|
||
public AssetLink hitPrefab = null; | ||
|
||
[ParameterMask] | ||
public int intersectionMask = ~0; | ||
|
||
private WorldIntersectionNormal hitInfo = new WorldIntersectionNormal(); | ||
|
||
private void Update() | ||
{ | ||
// устанавливаем текущую позицию пули | ||
Vec3 currentPosition = node.WorldPosition; | ||
// устанавливаем направление движения пули вдоль оси Y | ||
vec3 currentDirection = node.GetWorldDirection(MathLib.AXIS.Y); | ||
|
||
// обновляем положение пули вдоль траектории в соответствии с заданной скоростью | ||
node.WorldPosition += currentDirection * speed * Game.IFps; | ||
|
||
// ищем пересечение траектории пули с каким-либо объектом | ||
Unigine.Object hitObject = World.GetIntersection(currentPosition, node.WorldPosition, intersectionMask, hitInfo); | ||
|
||
// если пересечений не найдено, ничего не делаем | ||
if (!hitObject) | ||
return; | ||
|
||
// иначе загружаем NodeReference с эффектом попадания | ||
Node hitEffect = World.LoadNode(hitPrefab.AbsolutePath); | ||
// устанавливаем NodeReference в точку попадания и ориентируем его по нормали к поверхности | ||
hitEffect.Parent = hitObject; | ||
hitEffect.WorldPosition = hitInfo.Point; | ||
hitEffect.SetWorldDirection(hitInfo.Normal, vec3.UP, MathLib.AXIS.Y); | ||
|
||
// удаляем пулю | ||
node.DeleteLater(); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
data/csharp_template/FP_controller/components/Bullet.cs.meta
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<asset version="2.18.0.1"> | ||
<guid>27288c553eaee1ae73cc529616f559e6334c2941</guid> | ||
<type>component</type> | ||
<hash>0625c6a5</hash> | ||
<runtimes> | ||
<runtime id="27288c553eaee1ae73cc529616f559e6334c2941" name="Bullet.cs" link="0"/> | ||
<runtime id="88d6112b0032ace8365867c48dbe1958c29471f7" name="Bullet.prop" link="1" type="4"/> | ||
</runtimes> | ||
</asset> |
61 changes: 61 additions & 0 deletions
61
data/csharp_template/FP_controller/components/EnemyFireController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using Unigine; | ||
|
||
[Component(PropertyGuid = "7eb5cbfb6c98181a790c65d41fb95f354d95dfc7")] | ||
public class EnemyFireController : Component | ||
{ | ||
public Node leftMuzzle = null; | ||
public Node rightMuzzle = null; | ||
|
||
public AssetLink bulletPrefab = null; | ||
|
||
public float shootInterval = 1.0f; | ||
|
||
private float currentTime = 0.0f; | ||
private bool isLeft = false; | ||
private bool isFiring = false; | ||
|
||
public void StartFiring() | ||
{ | ||
isFiring = true; | ||
} | ||
|
||
public void StopFiring() | ||
{ | ||
isFiring = false; | ||
} | ||
|
||
private void Init() | ||
{ | ||
// сброс таймера | ||
currentTime = 0.0f; | ||
// переключаем стрельбу на правый ствол | ||
isLeft = false; | ||
} | ||
|
||
private void Update() | ||
{ | ||
// если робот не в состоянии атаки (Бездействие или Преследование), то ничего не делаем | ||
if (!isFiring) | ||
return; | ||
|
||
// обновляем таймер | ||
currentTime += Game.IFps; | ||
|
||
// проверка интервала стрельбы | ||
if (currentTime > shootInterval) | ||
{ | ||
// сброс таймера | ||
currentTime -= shootInterval; | ||
// создаем пулю из ассета назначенного в bulletPrefab | ||
Node bullet = World.LoadNode(bulletPrefab.AbsolutePath); | ||
|
||
// устанавливаем положение пули в зависимости от того, с какой стороны стреляем | ||
bullet.WorldTransform = (isLeft) ? leftMuzzle.WorldTransform : rightMuzzle.WorldTransform; | ||
// меняем ствол для следующего выстрела | ||
isLeft = !isLeft; | ||
|
||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
data/csharp_template/FP_controller/components/EnemyFireController.cs.meta
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<asset version="2.18.0.1"> | ||
<guid>4b3823a5c4fc24a3c73f5f268369b30430346791</guid> | ||
<type>component</type> | ||
<hash>7b1849b4</hash> | ||
<runtimes> | ||
<runtime id="4b3823a5c4fc24a3c73f5f268369b30430346791" name="EnemyFireController.cs" link="0"/> | ||
<runtime id="7eb5cbfb6c98181a790c65d41fb95f354d95dfc7" name="EnemyFireController.prop" link="1" type="4"/> | ||
</runtimes> | ||
</asset> |
Oops, something went wrong.