Skip to content

Commit 70623fb

Browse files
committed
Add infantry shooting logic and attack animation
Introduced bullet firing logic to Infantry, including ammunition management and prefab instantiation. Extended Vehicle and Infantry data models with shooting-related fields. Updated Infantry animation controller to support attack animations and transitions. Renamed and adjusted prefabs and animation assets to reflect new functionality.
1 parent 37debd6 commit 70623fb

File tree

9 files changed

+240
-63
lines changed

9 files changed

+240
-63
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ GameObject:
1515
- component: {fileID: -9073611661808193524}
1616
- component: {fileID: -4396582122761234523}
1717
m_Layer: 0
18-
m_Name: Sphere (1)
18+
m_Name: BulletDemo
1919
m_TagString: Untagged
2020
m_Icon: {fileID: 0}
2121
m_NavMeshLayer: 0
@@ -104,9 +104,9 @@ SphereCollider:
104104
serializedVersion: 2
105105
m_Bits: 0
106106
m_LayerOverridePriority: 0
107-
m_IsTrigger: 0
107+
m_IsTrigger: 1
108108
m_ProvidesContacts: 0
109-
m_Enabled: 0
109+
m_Enabled: 1
110110
serializedVersion: 3
111111
m_Radius: 0.5
112112
m_Center: {x: 0, y: 0, z: 0}

Red Strike/Assets/VehicleSystem/Vehicle.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,17 @@ public class Vehicle : ScriptableObject
77
{
88
public string vehicleName;
99
public float speed;
10+
public float coverageAreaRadius;
1011
public float turnSpeed;
1112
public float stoppingDistance;
1213
public float maxHealth;
1314
public float fuelCapacity;
1415
public float fuelConsumptionRate;
16+
public int maxAmmunition;
17+
public float bulletDamage;
18+
public float bulletSpeed;
19+
public float reloadTime;
20+
21+
public GameObject bulletPrefab;
1522
}
1623
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,14 @@ MonoBehaviour:
1414
m_EditorClassIdentifier:
1515
vehicleName: Infantry
1616
speed: 10
17+
coverageAreaRadius: 50
1718
turnSpeed: 5
1819
stoppingDistance: 5
1920
maxHealth: 100
2021
fuelCapacity: 100
2122
fuelConsumptionRate: 0.1
23+
maxAmmunition: 30
24+
bulletDamage: 20
25+
bulletSpeed: 50
26+
reloadTime: 0.7
27+
bulletPrefab: {fileID: 8699837864222786616, guid: beb6ea4d225a14c4184713da1d56a3e3, type: 3}

Red Strike/Assets/VehicleSystem/Vehicles/Infantry/Infantry.controller

Lines changed: 91 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,36 @@ AnimatorStateTransition:
2525
m_InterruptionSource: 0
2626
m_OrderedInterruption: 1
2727
m_CanTransitionToSelf: 1
28+
--- !u!1101 &-7794925093325067853
29+
AnimatorStateTransition:
30+
m_ObjectHideFlags: 1
31+
m_CorrespondingSourceObject: {fileID: 0}
32+
m_PrefabInstance: {fileID: 0}
33+
m_PrefabAsset: {fileID: 0}
34+
m_Name:
35+
m_Conditions: []
36+
m_DstStateMachine: {fileID: 0}
37+
m_DstState: {fileID: 7793613738655110020}
38+
m_Solo: 0
39+
m_Mute: 0
40+
m_IsExit: 0
41+
serializedVersion: 3
42+
m_TransitionDuration: 0.25
43+
m_TransitionOffset: 0
44+
m_ExitTime: 0.5588235
45+
m_HasExitTime: 1
46+
m_HasFixedDuration: 1
47+
m_InterruptionSource: 0
48+
m_OrderedInterruption: 1
49+
m_CanTransitionToSelf: 1
2850
--- !u!1102 &-3326796576763536756
2951
AnimatorState:
3052
serializedVersion: 6
3153
m_ObjectHideFlags: 1
3254
m_CorrespondingSourceObject: {fileID: 0}
3355
m_PrefabInstance: {fileID: 0}
3456
m_PrefabAsset: {fileID: 0}
35-
m_Name: InfantryVehicleStopAAnimation
57+
m_Name: StopA
3658
m_Speed: 1
3759
m_CycleOffset: 0
3860
m_Transitions:
@@ -77,6 +99,33 @@ AnimatorStateTransition:
7799
m_InterruptionSource: 0
78100
m_OrderedInterruption: 1
79101
m_CanTransitionToSelf: 1
102+
--- !u!1102 &-2260942612622049574
103+
AnimatorState:
104+
serializedVersion: 6
105+
m_ObjectHideFlags: 1
106+
m_CorrespondingSourceObject: {fileID: 0}
107+
m_PrefabInstance: {fileID: 0}
108+
m_PrefabAsset: {fileID: 0}
109+
m_Name: AttackA
110+
m_Speed: 1
111+
m_CycleOffset: 0
112+
m_Transitions:
113+
- {fileID: -7794925093325067853}
114+
m_StateMachineBehaviours: []
115+
m_Position: {x: 50, y: 50, z: 0}
116+
m_IKOnFeet: 0
117+
m_WriteDefaultValues: 1
118+
m_Mirror: 0
119+
m_SpeedParameterActive: 0
120+
m_MirrorParameterActive: 0
121+
m_CycleOffsetParameterActive: 0
122+
m_TimeParameterActive: 0
123+
m_Motion: {fileID: 7400000, guid: 6e6a6f313eae73b4e8ec8023fef3562d, type: 2}
124+
m_Tag:
125+
m_SpeedParameter:
126+
m_MirrorParameter:
127+
m_CycleOffsetParameter:
128+
m_TimeParameter:
80129
--- !u!1101 &-2092320670624703028
81130
AnimatorStateTransition:
82131
m_ObjectHideFlags: 1
@@ -157,6 +206,12 @@ AnimatorController:
157206
m_DefaultInt: 0
158207
m_DefaultBool: 0
159208
m_Controller: {fileID: 9100000}
209+
- m_Name: Attack
210+
m_Type: 9
211+
m_DefaultFloat: 0
212+
m_DefaultInt: 0
213+
m_DefaultBool: 0
214+
m_Controller: {fileID: 9100000}
160215
m_AnimatorLayers:
161216
- serializedVersion: 5
162217
m_Name: Base Layer
@@ -193,13 +248,16 @@ AnimatorStateMachine:
193248
m_Position: {x: 640, y: 100, z: 0}
194249
- serializedVersion: 1
195250
m_State: {fileID: 3945269039554599044}
196-
m_Position: {x: 280, y: 410, z: 0}
251+
m_Position: {x: 370, y: 400, z: 0}
252+
- serializedVersion: 1
253+
m_State: {fileID: -2260942612622049574}
254+
m_Position: {x: 130, y: 400, z: 0}
197255
m_ChildStateMachines: []
198256
m_AnyStateTransitions: []
199257
m_EntryTransitions: []
200258
m_StateMachineTransitions: {}
201259
m_StateMachineBehaviours: []
202-
m_AnyStatePosition: {x: 50, y: 20, z: 0}
260+
m_AnyStatePosition: {x: 50, y: 50, z: 0}
203261
m_EntryPosition: {x: 50, y: 120, z: 0}
204262
m_ExitPosition: {x: 40, y: 220, z: 0}
205263
m_ParentStateMachinePosition: {x: 800, y: 20, z: 0}
@@ -236,7 +294,7 @@ AnimatorState:
236294
m_CorrespondingSourceObject: {fileID: 0}
237295
m_PrefabInstance: {fileID: 0}
238296
m_PrefabAsset: {fileID: 0}
239-
m_Name: InfantryVehicleFirstCreatedAnimation
297+
m_Name: FirstCreated
240298
m_Speed: 1
241299
m_CycleOffset: 0
242300
m_Transitions:
@@ -284,14 +342,39 @@ AnimatorStateTransition:
284342
m_InterruptionSource: 0
285343
m_OrderedInterruption: 1
286344
m_CanTransitionToSelf: 1
345+
--- !u!1101 &2927619733231923867
346+
AnimatorStateTransition:
347+
m_ObjectHideFlags: 1
348+
m_CorrespondingSourceObject: {fileID: 0}
349+
m_PrefabInstance: {fileID: 0}
350+
m_PrefabAsset: {fileID: 0}
351+
m_Name:
352+
m_Conditions:
353+
- m_ConditionMode: 1
354+
m_ConditionEvent: Attack
355+
m_EventTreshold: 0
356+
m_DstStateMachine: {fileID: 0}
357+
m_DstState: {fileID: -2260942612622049574}
358+
m_Solo: 0
359+
m_Mute: 0
360+
m_IsExit: 0
361+
serializedVersion: 3
362+
m_TransitionDuration: 0.25
363+
m_TransitionOffset: 0
364+
m_ExitTime: 0.875
365+
m_HasExitTime: 1
366+
m_HasFixedDuration: 1
367+
m_InterruptionSource: 0
368+
m_OrderedInterruption: 1
369+
m_CanTransitionToSelf: 1
287370
--- !u!1102 &3945269039554599044
288371
AnimatorState:
289372
serializedVersion: 6
290373
m_ObjectHideFlags: 1
291374
m_CorrespondingSourceObject: {fileID: 0}
292375
m_PrefabInstance: {fileID: 0}
293376
m_PrefabAsset: {fileID: 0}
294-
m_Name: InfantryVehicleAttackAAnimation
377+
m_Name: AttackA_Copy
295378
m_Speed: 1
296379
m_CycleOffset: 0
297380
m_Transitions:
@@ -318,7 +401,7 @@ AnimatorState:
318401
m_CorrespondingSourceObject: {fileID: 0}
319402
m_PrefabInstance: {fileID: 0}
320403
m_PrefabAsset: {fileID: 0}
321-
m_Name: InfantryVehicleRunAAnimation
404+
m_Name: RunA
322405
m_Speed: 1
323406
m_CycleOffset: 0
324407
m_Transitions:
@@ -345,12 +428,13 @@ AnimatorState:
345428
m_CorrespondingSourceObject: {fileID: 0}
346429
m_PrefabInstance: {fileID: 0}
347430
m_PrefabAsset: {fileID: 0}
348-
m_Name: InfantryVehicleIdleAAnimation
431+
m_Name: IdleA
349432
m_Speed: 1
350433
m_CycleOffset: 0
351434
m_Transitions:
352435
- {fileID: 660612692531993009}
353436
- {fileID: -549571096820179978}
437+
- {fileID: 2927619733231923867}
354438
m_StateMachineBehaviours: []
355439
m_Position: {x: 50, y: 50, z: 0}
356440
m_IKOnFeet: 0

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

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,24 @@ protected override void MoveTo(Vector3 destination)
1212
BarrelAimAtTarget();
1313
}
1414

15-
public void Attack()
15+
protected override void FireShot()
1616
{
17-
// Infantry attack logic here
17+
base.FireShot();
18+
19+
BarrelAimAtTarget();
20+
21+
if (bulletPrefab != null && currentAmmunition > 0)
22+
{
23+
GameObject bullet = Instantiate(bulletPrefab, barrelTransform.position, barrelTransform.rotation);
24+
bullet.GetComponent<Rigidbody>().linearVelocity = barrelTransform.forward * bulletSpeed;
25+
26+
currentAmmunition--;
27+
}
28+
else if (currentAmmunition <= 0)
29+
{
30+
Debug.Log("Out of ammunition, reloading...");
31+
ReloadAmmunition();
32+
}
1833
}
1934

2035
public void Defend()
@@ -26,10 +41,5 @@ private void BarrelAimAtTarget()
2641
{
2742
// Aim the barrel towards the target object
2843
}
29-
30-
private void IdleAnimation()
31-
{
32-
33-
}
3444
}
3545
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ Animator:
235235
m_PrefabInstance: {fileID: 0}
236236
m_PrefabAsset: {fileID: 0}
237237
m_GameObject: {fileID: 224654450759790032}
238-
m_Enabled: 1
238+
m_Enabled: 0
239239
m_Avatar: {fileID: 0}
240240
m_Controller: {fileID: 9100000, guid: f154ca0c733b7d94bbbb3b7cacbabfa9, type: 2}
241241
m_CullingMode: 0

0 commit comments

Comments
 (0)