Skip to content

Commit 30224e8

Browse files
committed
Add explosion effect to tank shell and improve collision
Introduced an explosion effect for BasicTankShell on impact, with logic to prevent multiple explosions and self-collisions. Updated BasicTankShell prefab to reference the explosion effect. Adjusted TankCombat reload time, improved GroundVehicle combat direction handling, and made minor prefab and scene updates for TankCombat.
1 parent bd9c955 commit 30224e8

File tree

7 files changed

+107
-22
lines changed

7 files changed

+107
-22
lines changed

Red Strike/Assets/AmmunitionSystem/Ammunitions/Ammunitions/BasicRocket/BasicRocket.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ public class BasicRocket : Ammunition
1818
private void Awake()
1919
{
2020
rb = GetComponent<Rigidbody>();
21-
rb.useGravity = false;
2221
currentSpeed = speed * 0.5f;
2322
}
2423

Red Strike/Assets/AmmunitionSystem/Ammunitions/Ammunitions/BasicTankShell/BasicTankShell.cs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ namespace AmmunitionSystem.Ammunitions.Ammunitions.BasicTankShell
66
public class BasicTankShell : Ammunition
77
{
88
private Rigidbody rb;
9+
public GameObject explosionEffectPrefab;
10+
private bool hasExploded = false;
911

1012
private void Awake()
1113
{
@@ -15,20 +17,34 @@ private void Awake()
1517
private void Start()
1618
{
1719
rb.linearVelocity = transform.forward * ammunitionData.speed;
20+
Destroy(gameObject, ammunitionData.lifetime);
1821
}
1922

2023
private void OnCollisionEnter(Collision collision)
2124
{
22-
if (collision.gameObject.CompareTag("Enemy"))
25+
if (hasExploded) return;
26+
27+
if (ownerVehicle != null && collision.gameObject == ownerVehicle.gameObject)
28+
return;
29+
30+
if (collision.gameObject.CompareTag("Ammunition"))
31+
return;
32+
33+
hasExploded = true;
34+
35+
if (explosionEffectPrefab != null)
2336
{
24-
Debug.Log($"Hit enemy: {collision.gameObject.name}, Damage: {ammunitionData.damage}");
25-
// Here you would typically access the enemy's health component and apply damage
37+
GameObject explosionEffect = Instantiate(explosionEffectPrefab, transform.position, Quaternion.identity);
38+
Destroy(explosionEffect, 2f);
2639
}
2740

28-
if (ownerVehicle.gameObject != collision.gameObject)
41+
if (collision.gameObject.CompareTag("Enemy"))
2942
{
30-
Destroy(gameObject);
43+
Debug.Log($"Hit enemy: {collision.gameObject.name}, Damage: {ammunitionData.damage}");
44+
// örn: collision.gameObject.GetComponent<Health>()?.TakeDamage(ammunitionData.damage);
3145
}
46+
47+
Destroy(gameObject);
3248
}
3349
}
3450
}

Red Strike/Assets/AmmunitionSystem/Ammunitions/Ammunitions/BasicTankShell/BasicTankShell.prefab

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5053,6 +5053,7 @@ MonoBehaviour:
50535053
m_EditorClassIdentifier:
50545054
ammunitionData: {fileID: 11400000, guid: 5ef71d70c67b5bc4d964f8e71bd005ea, type: 2}
50555055
ownerVehicle: {fileID: 0}
5056+
explosionEffectPrefab: {fileID: 100006, guid: 2e7e92bc7175b744ea40878dedfa79e4, type: 3}
50565057
--- !u!54 &124524468962142996
50575058
Rigidbody:
50585059
m_ObjectHideFlags: 0

Red Strike/Assets/Scenes/GameScene.unity

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,67 @@ PrefabInstance:
10911091
m_AddedGameObjects: []
10921092
m_AddedComponents: []
10931093
m_SourcePrefab: {fileID: 100100000, guid: 16678156d05891545a8ea7f1b6b4e7f6, type: 3}
1094+
--- !u!1001 &1864555597
1095+
PrefabInstance:
1096+
m_ObjectHideFlags: 0
1097+
serializedVersion: 2
1098+
m_Modification:
1099+
serializedVersion: 3
1100+
m_TransformParent: {fileID: 0}
1101+
m_Modifications:
1102+
- target: {fileID: 2101350289756070789, guid: 9cf1c748f66b08149a5dd3ff27cb2a9b, type: 3}
1103+
propertyPath: m_Height
1104+
value: 11.01
1105+
objectReference: {fileID: 0}
1106+
- target: {fileID: 4592109742520757630, guid: 9cf1c748f66b08149a5dd3ff27cb2a9b, type: 3}
1107+
propertyPath: m_LocalPosition.x
1108+
value: 19.426407
1109+
objectReference: {fileID: 0}
1110+
- target: {fileID: 4592109742520757630, guid: 9cf1c748f66b08149a5dd3ff27cb2a9b, type: 3}
1111+
propertyPath: m_LocalPosition.y
1112+
value: 0
1113+
objectReference: {fileID: 0}
1114+
- target: {fileID: 4592109742520757630, guid: 9cf1c748f66b08149a5dd3ff27cb2a9b, type: 3}
1115+
propertyPath: m_LocalPosition.z
1116+
value: -65.34317
1117+
objectReference: {fileID: 0}
1118+
- target: {fileID: 4592109742520757630, guid: 9cf1c748f66b08149a5dd3ff27cb2a9b, type: 3}
1119+
propertyPath: m_LocalRotation.w
1120+
value: 1
1121+
objectReference: {fileID: 0}
1122+
- target: {fileID: 4592109742520757630, guid: 9cf1c748f66b08149a5dd3ff27cb2a9b, type: 3}
1123+
propertyPath: m_LocalRotation.x
1124+
value: 0
1125+
objectReference: {fileID: 0}
1126+
- target: {fileID: 4592109742520757630, guid: 9cf1c748f66b08149a5dd3ff27cb2a9b, type: 3}
1127+
propertyPath: m_LocalRotation.y
1128+
value: 0
1129+
objectReference: {fileID: 0}
1130+
- target: {fileID: 4592109742520757630, guid: 9cf1c748f66b08149a5dd3ff27cb2a9b, type: 3}
1131+
propertyPath: m_LocalRotation.z
1132+
value: 0
1133+
objectReference: {fileID: 0}
1134+
- target: {fileID: 4592109742520757630, guid: 9cf1c748f66b08149a5dd3ff27cb2a9b, type: 3}
1135+
propertyPath: m_LocalEulerAnglesHint.x
1136+
value: 0
1137+
objectReference: {fileID: 0}
1138+
- target: {fileID: 4592109742520757630, guid: 9cf1c748f66b08149a5dd3ff27cb2a9b, type: 3}
1139+
propertyPath: m_LocalEulerAnglesHint.y
1140+
value: 0
1141+
objectReference: {fileID: 0}
1142+
- target: {fileID: 4592109742520757630, guid: 9cf1c748f66b08149a5dd3ff27cb2a9b, type: 3}
1143+
propertyPath: m_LocalEulerAnglesHint.z
1144+
value: 0
1145+
objectReference: {fileID: 0}
1146+
- target: {fileID: 6447347669934246735, guid: 9cf1c748f66b08149a5dd3ff27cb2a9b, type: 3}
1147+
propertyPath: m_Name
1148+
value: TankCombat
1149+
objectReference: {fileID: 0}
1150+
m_RemovedComponents: []
1151+
m_RemovedGameObjects: []
1152+
m_AddedGameObjects: []
1153+
m_AddedComponents: []
1154+
m_SourcePrefab: {fileID: 100100000, guid: 9cf1c748f66b08149a5dd3ff27cb2a9b, type: 3}
10941155
--- !u!1660057539 &9223372036854775807
10951156
SceneRoots:
10961157
m_ObjectHideFlags: 0
@@ -1105,3 +1166,4 @@ SceneRoots:
11051166
- {fileID: 422005012}
11061167
- {fileID: 117385835}
11071168
- {fileID: 1772906554}
1169+
- {fileID: 1864555597}

Red Strike/Assets/VehicleSystem/Vehicles/GroundVehicle.cs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@ public class GroundVehicle : Vehicle
1111

1212
[Header("Ground Combat Settings")]
1313
// Agent'ın durma mesafesinden bağımsız olarak roket atabileceği maksimum mesafe.
14-
public float rocketAttackRange = 40f;
14+
public float rocketAttackRange = 40f;
1515

1616
protected override void Start()
1717
{
1818
base.Start();
1919

2020
agent = GetComponent<NavMeshAgent>();
21-
21+
2222
agent.speed = vehicleData.speed;
23-
agent.stoppingDistance = vehicleData.stoppingDistance;
23+
agent.stoppingDistance = vehicleData.stoppingDistance;
2424
agent.angularSpeed = vehicleData.turnSpeed;
25-
agent.updateRotation = false;
25+
agent.updateRotation = false;
2626
}
2727

2828
protected override void Update()
@@ -62,10 +62,10 @@ protected override void Update()
6262
}
6363
else
6464
{
65-
isMoving = false;
65+
isMoving = false;
6666
}
6767
}
68-
68+
6969
HandleCombat();
7070

7171
UpdateSmokeEffect();
@@ -76,10 +76,17 @@ private void HandleCombat()
7676
if (targetObject == null) return;
7777

7878
float distanceToTarget = Vector3.Distance(transform.position, targetObject.transform.position);
79-
79+
8080
Vector3 dirToTarget = (targetObject.transform.position - transform.position).normalized;
81+
dirToTarget.y = 0;
82+
83+
if (dirToTarget.sqrMagnitude < 0.001f)
84+
{
85+
dirToTarget = transform.forward;
86+
}
87+
8188
float angle = Vector3.Angle(transform.forward, dirToTarget);
82-
89+
8390
if (angle < 15f)
8491
{
8592
if (distanceToTarget <= rocketAttackRange)

Red Strike/Assets/VehicleSystem/Vehicles/TankCombat/TankCombat.asset

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ MonoBehaviour:
2626
- isEnabled: 1
2727
ammunitionType: 0
2828
maxAmmunition: 20
29-
reloadTime: 5
29+
reloadTime: 1
3030
ammunition: {fileID: 11400000, guid: 5ef71d70c67b5bc4d964f8e71bd005ea, type: 2}

Red Strike/Assets/VehicleSystem/Vehicles/TankCombat/TankCombat.prefab

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ ParticleSystem:
285285
m_RotationOrder: 4
286286
startSizeY:
287287
serializedVersion: 2
288-
minMaxState: 0
288+
minMaxState: 3
289289
scalar: 1
290290
minScalar: 1
291291
maxCurve:
@@ -338,7 +338,7 @@ ParticleSystem:
338338
m_RotationOrder: 4
339339
startSizeZ:
340340
serializedVersion: 2
341-
minMaxState: 0
341+
minMaxState: 3
342342
scalar: 1
343343
minScalar: 1
344344
maxCurve:
@@ -4837,7 +4837,7 @@ Transform:
48374837
m_GameObject: {fileID: 1097597481161462321}
48384838
serializedVersion: 2
48394839
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
4840-
m_LocalPosition: {x: -33.449257, y: 0, z: 103.476906}
4840+
m_LocalPosition: {x: 0, y: 0.835, z: -0.59}
48414841
m_LocalScale: {x: 1, y: 1, z: 1}
48424842
m_ConstrainProportionsScale: 0
48434843
m_Children: []
@@ -4853,9 +4853,9 @@ Light:
48534853
m_Enabled: 1
48544854
serializedVersion: 11
48554855
m_Type: 2
4856-
m_Color: {r: 1, g: 0.7502524, b: 0.6839622, a: 1}
4857-
m_Intensity: 3.3
4858-
m_Range: 0.8163952
4856+
m_Color: {r: 0.7921569, g: 0.2946453, b: 0, a: 1}
4857+
m_Intensity: 12.2
4858+
m_Range: 2.366142
48594859
m_SpotAngle: 30
48604860
m_InnerSpotAngle: 21.80208
48614861
m_CookieSize: 10
@@ -4893,7 +4893,7 @@ Light:
48934893
serializedVersion: 2
48944894
m_Bits: 4294967295
48954895
m_RenderingLayerMask: 1
4896-
m_Lightmapping: 4
4896+
m_Lightmapping: 1
48974897
m_LightShadowCasterMode: 0
48984898
m_AreaSize: {x: 1, y: 1}
48994899
m_BounceIntensity: 1

0 commit comments

Comments
 (0)