From 93faf526d58a1f3310c23852676caf65cd266cb8 Mon Sep 17 00:00:00 2001 From: Noah4ever <66632359+Noah4ever@users.noreply.github.com> Date: Tue, 9 Nov 2021 11:11:32 +0100 Subject: [PATCH] Weapon Pointing --- .../Player/Player Animation Test.prefab | 183 ++++++++++++++---- Assets/Scenes/TestScene.unity | 6 +- Assets/Scripts/Weapons/Shoot.cs | 23 ++- Packages/packages-lock.json | 4 +- ProjectSettings/ProjectVersion.txt | 4 +- 5 files changed, 172 insertions(+), 48 deletions(-) diff --git a/Assets/Prefabs/Player/Player Animation Test.prefab b/Assets/Prefabs/Player/Player Animation Test.prefab index 3cf621c..1f18b57 100644 --- a/Assets/Prefabs/Player/Player Animation Test.prefab +++ b/Assets/Prefabs/Player/Player Animation Test.prefab @@ -160,6 +160,37 @@ MonoBehaviour: m_EditorClassIdentifier: m_Weight: 1 m_Effectors: [] +--- !u!1 &427244160471813103 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 3995184887649218415} + m_Layer: 0 + m_Name: BulletExitPoint + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &3995184887649218415 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 427244160471813103} + m_LocalRotation: {x: 0, y: -0.7071068, z: 0, w: 0.7071068} + m_LocalPosition: {x: -0.1901, y: 0.0393, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 4058555163434875561} + m_RootOrder: 4 + m_LocalEulerAnglesHint: {x: 0, y: -90, z: 0} --- !u!1 &1122453500918594702 GameObject: m_ObjectHideFlags: 0 @@ -362,6 +393,29 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 48948dfe9d76b07488dacd46a7955fa1, type: 3} m_Name: m_EditorClassIdentifier: +--- !u!114 &4725102558119853970 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 3682030003239559187} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: c98f5c47a8b7dd64f86fd6f42c4d6e5e, type: 3} + m_Name: + m_EditorClassIdentifier: + weaponKind: 1 + active: 0 + damage: 10 + firerate: 320 + roundsPerShot: 1 + recoilStrength: 15 + currentAmmunition: 16 + magazinSize: 16 + totalAmmunition: 64 + bulletExit: {fileID: 0} + allowAction: 1 --- !u!1 &4824770690127859843 GameObject: m_ObjectHideFlags: 0 @@ -534,6 +588,51 @@ MonoBehaviour: m_hasFontAssetChanged: 0 m_renderer: {fileID: 763023871062575730} m_maskType: 0 +--- !u!1 &5628772214698948044 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 2573390158738433571} + - component: {fileID: 3277227182649658100} + m_Layer: 0 + m_Name: M92 + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &2573390158738433571 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5628772214698948044} + 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: 3087782655464804516} + m_Father: {fileID: 4074665071222326704} + m_RootOrder: 1 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &3277227182649658100 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5628772214698948044} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 48948dfe9d76b07488dacd46a7955fa1, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1 &6272346181302961293 GameObject: m_ObjectHideFlags: 0 @@ -552,12 +651,13 @@ GameObject: - component: {fileID: 5630859218361338035} - component: {fileID: 8436279266335313624} - component: {fileID: 268368477457052331} - - component: {fileID: 3781802212159559521} - component: {fileID: 6207632454083444980} - component: {fileID: 1509131218531316230} - component: {fileID: 8957579265169979397} - component: {fileID: 3965891812990671158} - component: {fileID: 4276885029697240453} + - component: {fileID: 5971405436260802329} + - component: {fileID: 4889600355201469534} m_Layer: 0 m_Name: Player Animation Test m_TagString: Player @@ -768,24 +868,6 @@ MonoBehaviour: stepAmplitudeSprinting: 0.07 stepFrequency: 0.8 Neck: {fileID: 6272346181657429396} ---- !u!114 &3781802212159559521 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 6272346181302961293} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: bc5bc2b49bd326e4db460a6a3af59311, type: 3} - m_Name: - m_EditorClassIdentifier: - syncMode: 0 - syncInterval: 0.1 - muzzle: {fileID: 3649358604728444914} - shootAnim: {fileID: 4276885029697240453} - fireRate: 320 - gunHoldPos: {fileID: 3682030003239559187} --- !u!114 &6207632454083444980 MonoBehaviour: m_ObjectHideFlags: 0 @@ -912,6 +994,37 @@ MonoBehaviour: returnForce: 0.006 impulsForce: 0.025 maxRecoil: 0.1 +--- !u!114 &5971405436260802329 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6272346181302961293} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 0f43c52a1834dcb4bab807bc0cbddec2, type: 3} + m_Name: + m_EditorClassIdentifier: + syncMode: 0 + syncInterval: 0.1 + muzzle: {fileID: 427244160471813103} + shootAnim: {fileID: 4276885029697240453} + gunHoldPos: {fileID: 0} + weaponHolder: {fileID: 3682030003239559187} + GunRotation: {fileID: 7768205653369755348} +--- !u!114 &4889600355201469534 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6272346181302961293} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 323a821a5fef23a45aa5333ce1f55202, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1 &6272346181657429393 GameObject: m_ObjectHideFlags: 0 @@ -1064,7 +1177,7 @@ Transform: m_ConstrainProportionsScale: 0 m_Children: - {fileID: 6035287771982183217} - - {fileID: 3087782655464804516} + - {fileID: 2573390158738433571} m_Father: {fileID: 6272346181657429396} m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -1169,14 +1282,14 @@ Transform: 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_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_Father: {fileID: 2573390158738433571} + m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &3590891737052679150 MonoBehaviour: @@ -1327,16 +1440,16 @@ PrefabInstance: objectReference: {fileID: 9100000, guid: daf332133edb41440a3abb1cf6e24558, type: 2} m_RemovedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: d1ac7df45c0d7e84993ff57afe3c4d6f, type: 3} ---- !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!1 &3682030003239559187 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 919132149155446097, guid: d1ac7df45c0d7e84993ff57afe3c4d6f, type: 3} + m_PrefabInstance: {fileID: 4600527171543473474} + m_PrefabAsset: {fileID: 0} --- !u!1001 &6305701708507383038 PrefabInstance: m_ObjectHideFlags: 0 @@ -1394,9 +1507,9 @@ PrefabInstance: objectReference: {fileID: 0} m_RemovedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: 01316cb596562384da845bc519fb90de, type: 3} ---- !u!1 &6576156620079053231 stripped -GameObject: - m_CorrespondingSourceObject: {fileID: 919132149155446097, guid: 01316cb596562384da845bc519fb90de, type: 3} +--- !u!4 &5767109144009335573 stripped +Transform: + m_CorrespondingSourceObject: {fileID: -8679921383154817045, guid: 01316cb596562384da845bc519fb90de, type: 3} m_PrefabInstance: {fileID: 6305701708507383038} m_PrefabAsset: {fileID: 0} --- !u!4 &8334588817950881727 stripped @@ -1429,8 +1542,8 @@ Transform: m_CorrespondingSourceObject: {fileID: -5815427104119794202, guid: 01316cb596562384da845bc519fb90de, type: 3} m_PrefabInstance: {fileID: 6305701708507383038} m_PrefabAsset: {fileID: 0} ---- !u!4 &5767109144009335573 stripped -Transform: - m_CorrespondingSourceObject: {fileID: -8679921383154817045, guid: 01316cb596562384da845bc519fb90de, type: 3} +--- !u!1 &6576156620079053231 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 919132149155446097, guid: 01316cb596562384da845bc519fb90de, type: 3} m_PrefabInstance: {fileID: 6305701708507383038} m_PrefabAsset: {fileID: 0} diff --git a/Assets/Scenes/TestScene.unity b/Assets/Scenes/TestScene.unity index b664d5a..b2146ba 100644 --- a/Assets/Scenes/TestScene.unity +++ b/Assets/Scenes/TestScene.unity @@ -38,7 +38,7 @@ RenderSettings: m_ReflectionIntensity: 1 m_CustomReflection: {fileID: 0} m_Sun: {fileID: 705507994} - m_IndirectSpecularColor: {r: 0.44657826, g: 0.49641263, b: 0.57481676, a: 1} + m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1} m_UseRadianceAmbientProbe: 0 --- !u!157 &3 LightmapSettings: @@ -303,6 +303,10 @@ PrefabInstance: m_Modification: m_TransformParent: {fileID: 0} m_Modifications: + - target: {fileID: 3094132477016057847, guid: b62548b3f87093b4dbc561f3dd1abcb8, type: 3} + propertyPath: playerPrefab + value: + objectReference: {fileID: 6272346181302961293, guid: a14d876ac00bdf6498e30b3e58b68fdf, type: 3} - target: {fileID: 3422988367618467032, guid: b62548b3f87093b4dbc561f3dd1abcb8, type: 3} propertyPath: m_Name value: GameManager diff --git a/Assets/Scripts/Weapons/Shoot.cs b/Assets/Scripts/Weapons/Shoot.cs index a273ea2..1ad249a 100644 --- a/Assets/Scripts/Weapons/Shoot.cs +++ b/Assets/Scripts/Weapons/Shoot.cs @@ -59,23 +59,30 @@ public class Shoot : NetworkBehaviour // This code will be executed on the Server. private void CmdFireBullet() { + Debug.Log(mCamera.transform.forward); + Vector3 hitpos; RaycastHit hit; Ray ray = new Ray(mCamera.transform.position, mCamera.transform.forward); - Physics.Raycast(ray, out crosshairHitPoint, 5000f); - - if (crosshairHitPoint.distance != 0 && crosshairHitPoint.distance < 2) // Turning Weapon to shooting point - { - _pointDirection = crosshairHitPoint.point - muzzle.transform.position; - _lookRotation = Quaternion.LookRotation(_pointDirection); - GunRotation.transform.rotation = Quaternion.RotateTowards(GunRotation.transform.rotation, _lookRotation, 1f); + if(Physics.Raycast(ray, out crosshairHitPoint, 5000f)){ + + hitpos = crosshairHitPoint.point; } + else + { + hitpos = mCamera.transform.position + mCamera.transform.forward * 5000; + } + _pointDirection = hitpos - muzzle.transform.position; + _lookRotation = Quaternion.LookRotation(_pointDirection); + GunRotation.transform.rotation = Quaternion.RotateTowards(GunRotation.transform.rotation, _lookRotation, 1f); if (weapon.AllowAction) // shooting { + shootAnimation(); if (Physics.Raycast(muzzle.transform.position, muzzle.transform.forward, out hit) && weapon.CurrentAmmunition > 0) { Debug.DrawLine(muzzle.transform.position, hit.point); - Debug.Log("Geshooted BITCH"); + + Debug.Log("Distance: " + hit.distance); if (hit.transform.gameObject.GetComponent() != null) { Debug.Log("GETROFFEN------------------"); diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json index c01782a..b479120 100644 --- a/Packages/packages-lock.json +++ b/Packages/packages-lock.json @@ -18,7 +18,7 @@ "url": "https://packages.unity.com" }, "com.unity.burst": { - "version": "1.5.6", + "version": "1.6.0", "depth": 1, "source": "registry", "dependencies": { @@ -69,7 +69,7 @@ "url": "https://packages.unity.com" }, "com.unity.mathematics": { - "version": "1.2.1", + "version": "1.2.4", "depth": 2, "source": "registry", "dependencies": {}, diff --git a/ProjectSettings/ProjectVersion.txt b/ProjectSettings/ProjectVersion.txt index 370f59d..03f4c05 100644 --- a/ProjectSettings/ProjectVersion.txt +++ b/ProjectSettings/ProjectVersion.txt @@ -1,2 +1,2 @@ -m_EditorVersion: 2021.1.25f1 -m_EditorVersionWithRevision: 2021.1.25f1 (b6f2b893ea32) +m_EditorVersion: 2021.2.0f1 +m_EditorVersionWithRevision: 2021.2.0f1 (4bf1ec4b23c9)