Skip to content

Commit 6059b95

Browse files
committed
Refactor dual-barrel firing for OrnithopterA and TankCombat
Updated OrnithopterA and TankCombat to use dual barrel points for firing, instantiating two bullets per shot and adjusting ammunition accordingly. Simplified and unified barrel transform and targeting logic. Updated prefabs and scene references to match new structure.
1 parent 6ffe4dc commit 6059b95

File tree

3 files changed

+113
-19
lines changed

3 files changed

+113
-19
lines changed

Red Strike/Assets/Scenes/SampleScene.unity

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4899,26 +4899,10 @@ PrefabInstance:
48994899
serializedVersion: 3
49004900
m_TransformParent: {fileID: 0}
49014901
m_Modifications:
4902-
- target: {fileID: -2782345837604721076, guid: a35a82b670e35ac4aa3594152075595d, type: 3}
4903-
propertyPath: bankSpeed
4904-
value: 30
4905-
objectReference: {fileID: 0}
4906-
- target: {fileID: -2782345837604721076, guid: a35a82b670e35ac4aa3594152075595d, type: 3}
4907-
propertyPath: maxBankAngle
4908-
value: 100
4909-
objectReference: {fileID: 0}
49104902
- target: {fileID: -2782345837604721076, guid: a35a82b670e35ac4aa3594152075595d, type: 3}
49114903
propertyPath: targetObject
49124904
value:
49134905
objectReference: {fileID: 460729958}
4914-
- target: {fileID: -2782345837604721076, guid: a35a82b670e35ac4aa3594152075595d, type: 3}
4915-
propertyPath: attackAltitude
4916-
value: 7
4917-
objectReference: {fileID: 0}
4918-
- target: {fileID: -2782345837604721076, guid: a35a82b670e35ac4aa3594152075595d, type: 3}
4919-
propertyPath: attackLobeRadius
4920-
value: 50
4921-
objectReference: {fileID: 0}
49224906
- target: {fileID: 4442516632743243454, guid: a35a82b670e35ac4aa3594152075595d, type: 3}
49234907
propertyPath: m_LocalPosition.x
49244908
value: 14.97344

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,47 @@ namespace VehicleSystem.Vehicles.OrnithopterA
55
{
66
public class OrnithopterA : AirVehicle
77
{
8+
public Transform barrelPoint_A;
9+
public Transform barrelPoint_B;
10+
public Transform barrelTransform;
811

12+
protected override void Update()
13+
{
14+
base.Update();
15+
16+
if (targetObject != null && isAttacking)
17+
{
18+
LookAtTarget(targetObject.transform);
19+
}
20+
}
21+
22+
protected override void FireShot()
23+
{
24+
base.FireShot();
25+
26+
if (bulletPrefab != null && currentAmmunition > 0)
27+
{
28+
GameObject bullet_A = Instantiate(bulletPrefab, barrelPoint_A.position, barrelPoint_A.rotation);
29+
bullet_A.GetComponent<Rigidbody>().linearVelocity = barrelPoint_A.forward * bulletSpeed;
30+
31+
GameObject bullet_B = Instantiate(bulletPrefab, barrelPoint_B.position, barrelPoint_B.rotation);
32+
bullet_B.GetComponent<Rigidbody>().linearVelocity = barrelPoint_B.forward * bulletSpeed;
33+
34+
currentAmmunition -= 2;
35+
}
36+
else if (currentAmmunition <= 0)
37+
{
38+
Debug.Log("Out of ammunition, reloading...");
39+
ReloadAmmunition();
40+
}
41+
}
42+
43+
private void LookAtTarget(Transform target)
44+
{
45+
Vector3 directionToTarget = target.position - barrelTransform.position;
46+
Vector3 localDirection = transform.InverseTransformDirection(directionToTarget);
47+
Quaternion targetLocalRotation = Quaternion.LookRotation(localDirection);
48+
barrelTransform.localRotation = Quaternion.Slerp(barrelTransform.localRotation, targetLocalRotation, Time.deltaTime * turnSpeed);
49+
}
950
}
1051
}

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

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ Transform:
3030
m_LocalPosition: {x: -0, y: 0.3228711, z: 1.0427506}
3131
m_LocalScale: {x: 1, y: 1, z: 1}
3232
m_ConstrainProportionsScale: 0
33-
m_Children: []
33+
m_Children:
34+
- {fileID: 4048120109068463893}
35+
- {fileID: 6325185049854432032}
3436
m_Father: {fileID: 4442516632743243454}
3537
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
3638
--- !u!33 &710270692257627436
@@ -453,9 +455,14 @@ MonoBehaviour:
453455
targetObject: {fileID: 0}
454456
smokeEffect: {fileID: 8772498824888722677}
455457
cruisingAltitude: 35
456-
attackAltitude: 10
457-
attackLobeRadius: 70
458+
attackAltitude: 7
459+
attackLobeRadius: 50
458460
loiterRadius: 40
461+
maxBankAngle: 100
462+
bankSpeed: 30
463+
barrelPoint_A: {fileID: 4048120109068463893}
464+
barrelPoint_B: {fileID: 6325185049854432032}
465+
barrelTransform: {fileID: 4166134374202684327}
459466
--- !u!65 &8976528752417907667
460467
BoxCollider:
461468
m_ObjectHideFlags: 0
@@ -564,6 +571,68 @@ MeshRenderer:
564571
m_SortingLayer: 0
565572
m_SortingOrder: 0
566573
m_AdditionalVertexStreams: {fileID: 0}
574+
--- !u!1 &8147949250731462183
575+
GameObject:
576+
m_ObjectHideFlags: 0
577+
m_CorrespondingSourceObject: {fileID: 0}
578+
m_PrefabInstance: {fileID: 0}
579+
m_PrefabAsset: {fileID: 0}
580+
serializedVersion: 6
581+
m_Component:
582+
- component: {fileID: 6325185049854432032}
583+
m_Layer: 6
584+
m_Name: BarrelPoint_B
585+
m_TagString: Untagged
586+
m_Icon: {fileID: 0}
587+
m_NavMeshLayer: 0
588+
m_StaticEditorFlags: 0
589+
m_IsActive: 1
590+
--- !u!4 &6325185049854432032
591+
Transform:
592+
m_ObjectHideFlags: 0
593+
m_CorrespondingSourceObject: {fileID: 0}
594+
m_PrefabInstance: {fileID: 0}
595+
m_PrefabAsset: {fileID: 0}
596+
m_GameObject: {fileID: 8147949250731462183}
597+
serializedVersion: 2
598+
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
599+
m_LocalPosition: {x: 0.204, y: -0.072999954, z: 0.9889984}
600+
m_LocalScale: {x: 1, y: 1, z: 1}
601+
m_ConstrainProportionsScale: 0
602+
m_Children: []
603+
m_Father: {fileID: 4166134374202684327}
604+
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
605+
--- !u!1 &8377260624438740236
606+
GameObject:
607+
m_ObjectHideFlags: 0
608+
m_CorrespondingSourceObject: {fileID: 0}
609+
m_PrefabInstance: {fileID: 0}
610+
m_PrefabAsset: {fileID: 0}
611+
serializedVersion: 6
612+
m_Component:
613+
- component: {fileID: 4048120109068463893}
614+
m_Layer: 6
615+
m_Name: BarrelPoint_A
616+
m_TagString: Untagged
617+
m_Icon: {fileID: 0}
618+
m_NavMeshLayer: 0
619+
m_StaticEditorFlags: 0
620+
m_IsActive: 1
621+
--- !u!4 &4048120109068463893
622+
Transform:
623+
m_ObjectHideFlags: 0
624+
m_CorrespondingSourceObject: {fileID: 0}
625+
m_PrefabInstance: {fileID: 0}
626+
m_PrefabAsset: {fileID: 0}
627+
m_GameObject: {fileID: 8377260624438740236}
628+
serializedVersion: 2
629+
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
630+
m_LocalPosition: {x: -0.198, y: -0.073, z: 0.989}
631+
m_LocalScale: {x: 1, y: 1, z: 1}
632+
m_ConstrainProportionsScale: 0
633+
m_Children: []
634+
m_Father: {fileID: 4166134374202684327}
635+
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
567636
--- !u!1001 &2734929954258652001
568637
PrefabInstance:
569638
m_ObjectHideFlags: 0

0 commit comments

Comments
 (0)