Full Recoil animation

This commit is contained in:
juliuse98
2021-11-08 12:55:58 +01:00
parent 352e22225f
commit c6cd50a4f8
8 changed files with 503 additions and 140 deletions

View File

@@ -71,15 +71,15 @@ ModelImporter:
name: Idle
takeName: Armature|ArmatureAction
internalID: 0
firstFrame: 25
lastFrame: 40
firstFrame: 24
lastFrame: 25
wrapMode: 0
orientationOffsetY: 0
level: 0
cycleOffset: 0
loop: 0
hasAdditiveReferencePose: 0
loopTime: 1
loopTime: 0
loopBlend: 0
loopBlendOrientation: 0
loopBlendPositionY: 0

View File

@@ -160,6 +160,103 @@ MonoBehaviour:
m_EditorClassIdentifier:
m_Weight: 1
m_Effectors: []
--- !u!1 &1122453500918594702
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 6035287771982183217}
- component: {fileID: 562931964943938264}
- component: {fileID: 7322695044511352809}
- component: {fileID: 492736715721067422}
m_Layer: 0
m_Name: Mid
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
--- !u!4 &6035287771982183217
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1122453500918594702}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0.01, y: 0.01, z: 0.01}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 4074665071222326704}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!33 &562931964943938264
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1122453500918594702}
m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0}
--- !u!23 &7322695044511352809
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1122453500918594702}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_StaticShadowCaster: 0
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RayTraceProcedural: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_AdditionalVertexStreams: {fileID: 0}
--- !u!135 &492736715721067422
SphereCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1122453500918594702}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Radius: 0.5
m_Center: {x: 0, y: 0, z: 0}
--- !u!1 &1749713556945343754
GameObject:
m_ObjectHideFlags: 0
@@ -798,9 +895,22 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
gun: {fileID: 3682030003239559187}
zOffset: 0
gunHolder: {fileID: 6522444664664986769}
gunPositionObj: {fileID: 7263663517583319679}
gunRotationObj: {fileID: 7768205653369755348}
positionRecoil: 1
rotationRecoil: 1
positionMultX: 0.1
positionMultY: 0.1
positionMultZ: 1
rotX: 1
rotationMultX: 25
rotY: 1
rotationMultY: 25
rotZ: 1
rotationMultZ: 15
returnForce: 0.006
impulsForce: 0.03
impulsForce: 0.025
maxRecoil: 0.1
--- !u!1 &6272346181657429393
GameObject:
@@ -835,7 +945,6 @@ Transform:
- {fileID: 5021921342190399731}
- {fileID: 4074665071222326704}
- {fileID: 1979435770070801855}
- {fileID: 4058555163434875561}
m_Father: {fileID: 981273033772084037}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@@ -934,6 +1043,7 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 4074665071222326704}
- component: {fileID: 909517976577723968}
m_Layer: 0
m_Name: GunHoldPoint
m_TagString: Untagged
@@ -949,13 +1059,27 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6522444664664986769}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: -0.056, z: 0.4}
m_LocalPosition: {x: 0, y: -0.005, z: 0.5}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Children:
- {fileID: 6035287771982183217}
- {fileID: 3087782655464804516}
m_Father: {fileID: 6272346181657429396}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &909517976577723968
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6522444664664986769}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 48948dfe9d76b07488dacd46a7955fa1, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!95 &1978909962
Animator:
serializedVersion: 4
@@ -1021,6 +1145,96 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 48948dfe9d76b07488dacd46a7955fa1, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &7263663517583319679
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 3087782655464804516}
- component: {fileID: 3590891737052679150}
m_Layer: 0
m_Name: GunPosition
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &3087782655464804516
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7263663517583319679}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 2848367205963120269}
m_Father: {fileID: 4074665071222326704}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &3590891737052679150
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7263663517583319679}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 48948dfe9d76b07488dacd46a7955fa1, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &7768205653369755348
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2848367205963120269}
- component: {fileID: 8468733188726769796}
m_Layer: 0
m_Name: GunRotation
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &2848367205963120269
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7768205653369755348}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 4058555163434875561}
m_Father: {fileID: 3087782655464804516}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &8468733188726769796
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7768205653369755348}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 48948dfe9d76b07488dacd46a7955fa1, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &8043317747957554736
GameObject:
m_ObjectHideFlags: 0
@@ -1045,7 +1259,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8043317747957554736}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: -0.15000013, z: 0}
m_LocalPosition: {x: 0, y: -0.0500001, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
@@ -1057,11 +1271,11 @@ PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 6272346181657429396}
m_TransformParent: {fileID: 2848367205963120269}
m_Modifications:
- target: {fileID: -8679921383154817045, guid: d1ac7df45c0d7e84993ff57afe3c4d6f, type: 3}
propertyPath: m_RootOrder
value: 3
value: 0
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: d1ac7df45c0d7e84993ff57afe3c4d6f, type: 3}
propertyPath: m_LocalPosition.x
@@ -1069,11 +1283,11 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: d1ac7df45c0d7e84993ff57afe3c4d6f, type: 3}
propertyPath: m_LocalPosition.y
value: -0.056000024
value: -0.054000046
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: d1ac7df45c0d7e84993ff57afe3c4d6f, type: 3}
propertyPath: m_LocalPosition.z
value: 0.4
value: -0.13
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: d1ac7df45c0d7e84993ff57afe3c4d6f, type: 3}
propertyPath: m_LocalRotation.w
@@ -1081,7 +1295,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: d1ac7df45c0d7e84993ff57afe3c4d6f, type: 3}
propertyPath: m_LocalRotation.x
value: 0
value: -0
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: d1ac7df45c0d7e84993ff57afe3c4d6f, type: 3}
propertyPath: m_LocalRotation.y
@@ -1089,7 +1303,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: d1ac7df45c0d7e84993ff57afe3c4d6f, type: 3}
propertyPath: m_LocalRotation.z
value: 0
value: -0
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: d1ac7df45c0d7e84993ff57afe3c4d6f, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
@@ -1113,16 +1327,16 @@ PrefabInstance:
objectReference: {fileID: 9100000, guid: daf332133edb41440a3abb1cf6e24558, type: 2}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: d1ac7df45c0d7e84993ff57afe3c4d6f, type: 3}
--- !u!4 &4058555163434875561 stripped
Transform:
m_CorrespondingSourceObject: {fileID: -8679921383154817045, guid: d1ac7df45c0d7e84993ff57afe3c4d6f, type: 3}
m_PrefabInstance: {fileID: 4600527171543473474}
m_PrefabAsset: {fileID: 0}
--- !u!1 &3682030003239559187 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 919132149155446097, guid: d1ac7df45c0d7e84993ff57afe3c4d6f, type: 3}
m_PrefabInstance: {fileID: 4600527171543473474}
m_PrefabAsset: {fileID: 0}
--- !u!4 &4058555163434875561 stripped
Transform:
m_CorrespondingSourceObject: {fileID: -8679921383154817045, guid: d1ac7df45c0d7e84993ff57afe3c4d6f, type: 3}
m_PrefabInstance: {fileID: 4600527171543473474}
m_PrefabAsset: {fileID: 0}
--- !u!1001 &6305701708507383038
PrefabInstance:
m_ObjectHideFlags: 0
@@ -1185,9 +1399,9 @@ GameObject:
m_CorrespondingSourceObject: {fileID: 919132149155446097, guid: 01316cb596562384da845bc519fb90de, type: 3}
m_PrefabInstance: {fileID: 6305701708507383038}
m_PrefabAsset: {fileID: 0}
--- !u!4 &5767109144009335573 stripped
--- !u!4 &8334588817950881727 stripped
Transform:
m_CorrespondingSourceObject: {fileID: -8679921383154817045, guid: 01316cb596562384da845bc519fb90de, type: 3}
m_CorrespondingSourceObject: {fileID: -6617984589164989631, guid: 01316cb596562384da845bc519fb90de, type: 3}
m_PrefabInstance: {fileID: 6305701708507383038}
m_PrefabAsset: {fileID: 0}
--- !u!4 &5739201115059209923 stripped
@@ -1215,8 +1429,8 @@ Transform:
m_CorrespondingSourceObject: {fileID: -5815427104119794202, guid: 01316cb596562384da845bc519fb90de, type: 3}
m_PrefabInstance: {fileID: 6305701708507383038}
m_PrefabAsset: {fileID: 0}
--- !u!4 &8334588817950881727 stripped
--- !u!4 &5767109144009335573 stripped
Transform:
m_CorrespondingSourceObject: {fileID: -6617984589164989631, guid: 01316cb596562384da845bc519fb90de, type: 3}
m_CorrespondingSourceObject: {fileID: -8679921383154817045, guid: 01316cb596562384da845bc519fb90de, type: 3}
m_PrefabInstance: {fileID: 6305701708507383038}
m_PrefabAsset: {fileID: 0}

View File

@@ -207,6 +207,103 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &453716095
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 4636852677861728898, guid: e4f2c82228df5bc4f8fc674e98c7275b, type: 3}
propertyPath: m_Pivot.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4636852677861728898, guid: e4f2c82228df5bc4f8fc674e98c7275b, type: 3}
propertyPath: m_Pivot.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4636852677861728898, guid: e4f2c82228df5bc4f8fc674e98c7275b, type: 3}
propertyPath: m_RootOrder
value: 4
objectReference: {fileID: 0}
- target: {fileID: 4636852677861728898, guid: e4f2c82228df5bc4f8fc674e98c7275b, type: 3}
propertyPath: m_AnchorMax.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4636852677861728898, guid: e4f2c82228df5bc4f8fc674e98c7275b, type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4636852677861728898, guid: e4f2c82228df5bc4f8fc674e98c7275b, type: 3}
propertyPath: m_AnchorMin.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4636852677861728898, guid: e4f2c82228df5bc4f8fc674e98c7275b, type: 3}
propertyPath: m_AnchorMin.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4636852677861728898, guid: e4f2c82228df5bc4f8fc674e98c7275b, type: 3}
propertyPath: m_SizeDelta.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4636852677861728898, guid: e4f2c82228df5bc4f8fc674e98c7275b, type: 3}
propertyPath: m_SizeDelta.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4636852677861728898, guid: e4f2c82228df5bc4f8fc674e98c7275b, type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4636852677861728898, guid: e4f2c82228df5bc4f8fc674e98c7275b, type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4636852677861728898, guid: e4f2c82228df5bc4f8fc674e98c7275b, type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4636852677861728898, guid: e4f2c82228df5bc4f8fc674e98c7275b, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4636852677861728898, guid: e4f2c82228df5bc4f8fc674e98c7275b, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4636852677861728898, guid: e4f2c82228df5bc4f8fc674e98c7275b, type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4636852677861728898, guid: e4f2c82228df5bc4f8fc674e98c7275b, type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4636852677861728898, guid: e4f2c82228df5bc4f8fc674e98c7275b, type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4636852677861728898, guid: e4f2c82228df5bc4f8fc674e98c7275b, type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4636852677861728898, guid: e4f2c82228df5bc4f8fc674e98c7275b, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4636852677861728898, guid: e4f2c82228df5bc4f8fc674e98c7275b, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4636852677861728898, guid: e4f2c82228df5bc4f8fc674e98c7275b, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4636852677861728911, guid: e4f2c82228df5bc4f8fc674e98c7275b, type: 3}
propertyPath: m_Name
value: DebugCanvas
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: e4f2c82228df5bc4f8fc674e98c7275b, type: 3}
--- !u!1 &518996702
GameObject:
m_ObjectHideFlags: 0
@@ -398,17 +495,13 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
--- !u!1001 &1728263333
--- !u!1001 &2086555069
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 3094132477016057847, guid: b62548b3f87093b4dbc561f3dd1abcb8, type: 3}
propertyPath: onlineScene
value: Assets/Scenes/Animation Test.unity
objectReference: {fileID: 0}
- target: {fileID: 3094132477016057847, guid: b62548b3f87093b4dbc561f3dd1abcb8, type: 3}
propertyPath: playerPrefab
value:

View File

@@ -1039,6 +1039,10 @@ PrefabInstance:
propertyPath: m_Name
value: DebugCanvas
objectReference: {fileID: 0}
- target: {fileID: 4636852677861728911, guid: e4f2c82228df5bc4f8fc674e98c7275b, type: 3}
propertyPath: m_IsActive
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4636852677968575729, guid: e4f2c82228df5bc4f8fc674e98c7275b, type: 3}
propertyPath: m_text
value: '[J] Lock Cursor | [H] Unlock Cursor'

View File

@@ -23,8 +23,6 @@ public class Shoot : NetworkBehaviour
{
if (Input.GetKeyDown(KeyCode.Mouse0))
{
//CmdFireBullet();
//RpcOnFire();
CmdFireBullet();
}
}
@@ -55,7 +53,6 @@ public class Shoot : NetworkBehaviour
// This code will be executed on the Client.
void shootAnimation()
{
//shootAnim.StartShootAnimation(fireRate);
shootAnim.recoil(gunHoldPos,0.1f);
}
}

View File

@@ -4,34 +4,63 @@ using UnityEngine;
public class ShootAnimation : MonoBehaviour
{
private Animator anim;
[SerializeField] private GameObject gun;
private Transform startTransform;
Vector3 startPos;
Vector3 startRot;
[SerializeField] float zOffset = 0f;
[SerializeField] float returnForce = 0.06f;
[SerializeField] float impulsForce = 0.2f;
[SerializeField] float maxRecoil = 0.5f;
private int recoilCounter = 0;
[Header("GameObjects")]
[SerializeField] private GameObject gun;
[SerializeField] private GameObject gunHolder;
[SerializeField] private GameObject gunPositionObj;
[SerializeField] private GameObject gunRotationObj;
[Header("Settings")]
[SerializeField] bool positionRecoil = true;
[SerializeField] bool rotationRecoil = true;
[Header("Position Settings")]
[SerializeField] float positionMultX = 25f;
[SerializeField] float positionMultY = 25f;
[SerializeField] float positionMultZ = 25f;
[Header("Rotation Settings")]
[SerializeField] bool rotX = true;
[SerializeField] float rotationMultX = 25f;
[SerializeField] bool rotY = true;
[SerializeField] float rotationMultY = 25f;
[SerializeField] bool rotZ = true;
[SerializeField] float rotationMultZ = 15f;
[SerializeField] float returnForce = 0.006f;
[SerializeField] float impulsForce = 0.025f;
[SerializeField] float maxRecoil = 0.1f;
private Animator anim;
Vector3 startPos,startRot;
float zOffset = 0f;
float zVelocity = 0f;
int recoilCounter = 0;
//Has to be called once at the beginning and then again when switching guns
public void OnSwitchWeapon(float fireRate)
{
//gun = newGun;
anim = gun.GetComponent<Animator>();
anim.SetFloat("ShootSpeed",1f/(60f/fireRate));
startPos = gun.transform.localPosition;
startRot = gun.transform.localRotation.eulerAngles;
startPos = gunPositionObj.transform.localPosition;
startRot = gunRotationObj.transform.localRotation.eulerAngles;
}
public void recoil(GameObject gun, float force)
{
//Play the animation
anim.Play("Shoot");
//Add force for the recoil
recoilCounter++;
}
@@ -58,8 +87,43 @@ public class ShootAnimation : MonoBehaviour
zVelocity += returnForce * 0.9f + returnForce * 0.1f * Mathf.PerlinNoise(Time.time,1f);
}
zOffset = Mathf.Clamp(zOffset,-maxRecoil * 0.5f + -maxRecoil * 0.5f * Mathf.PerlinNoise(Time.time * 1000,1),0);
gun.transform.localPosition = startPos + new Vector3(0,0,zOffset);
gun.transform.localRotation = Quaternion.Euler(startRot.x,startRot.y,startRot.z + zOffset * 50f);
zOffset = Mathf.Clamp(zOffset,-maxRecoil * 0.5f + -maxRecoil * 0.5f * Mathf.PerlinNoise(Time.time * 1000,1),0);
//Position recoil
if (positionRecoil)
{
gunPositionObj.transform.localPosition = startPos + new Vector3(
positionMultX * zOffset * ((Mathf.PerlinNoise(Time.time * 1f + 10f, 1f) - 0.5f) * 2f),
positionMultY * zOffset * ((Mathf.PerlinNoise(Time.time * 2f + 20f, 2f) - 0.5f) * 2f),
positionMultZ* zOffset * ((Mathf.PerlinNoise(Time.time * 3f + 30f, 3f) - 0.5f) * 2f));
}
else
{
gunPositionObj.transform.localPosition = startPos;
}
//Rotation recoil
if (rotationRecoil)
{
int xLock = 0;
int yLock = 0;
int zLock = 0;
if (rotX) xLock = 1;
if (rotY) yLock = 1;
if (rotZ) zLock = 1;
gunRotationObj.transform.localRotation = Quaternion.Euler(
startRot.x + xLock * rotationMultX * zOffset * ((Mathf.PerlinNoise(Time.time * 3f + 30f, 4f) - 0.5f) * 2f),
startRot.y + yLock * rotationMultY * zOffset * ((Mathf.PerlinNoise(Time.time * 2f + 10f, 3f) - 0.5f) * 2f),
startRot.z + zLock * rotationMultZ * zOffset * ((Mathf.PerlinNoise(Time.time * 1.5f, 2f) - 0.5f) * 2f));
}
else
{
gunRotationObj.transform.localRotation = Quaternion.Euler(startRot.x, startRot.y, startRot.z);
}
}
}