From a057798e3e8fe5986edbb9e6b5c1fee694e1ca48 Mon Sep 17 00:00:00 2001 From: Garrett Kaiser Date: Mon, 17 Nov 2025 15:30:29 -0800 Subject: [PATCH] GUN NO ROTATE :( --- Assets/Materials/leaf.mat | 3 ++- Assets/Materials/trunk.mat | 3 ++- Assets/Prefabs/ThrownGun.prefab | 4 ++-- Assets/Scripts/GunThrown.cs | 26 ++++++++++++++++++++++++-- Assets/Scripts/ThrowerEnemy.cs | 2 +- 5 files changed, 31 insertions(+), 7 deletions(-) diff --git a/Assets/Materials/leaf.mat b/Assets/Materials/leaf.mat index 7e8c3b7..ab1d39e 100644 --- a/Assets/Materials/leaf.mat +++ b/Assets/Materials/leaf.mat @@ -20,7 +20,8 @@ Material: m_DoubleSidedGI: 0 m_CustomRenderQueue: -1 stringTagMap: {} - disabledShaderPasses: [] + disabledShaderPasses: + - MOTIONVECTORS m_LockedProperties: m_SavedProperties: serializedVersion: 3 diff --git a/Assets/Materials/trunk.mat b/Assets/Materials/trunk.mat index ba3e0e4..aec35c9 100644 --- a/Assets/Materials/trunk.mat +++ b/Assets/Materials/trunk.mat @@ -20,7 +20,8 @@ Material: m_DoubleSidedGI: 0 m_CustomRenderQueue: -1 stringTagMap: {} - disabledShaderPasses: [] + disabledShaderPasses: + - MOTIONVECTORS m_LockedProperties: m_SavedProperties: serializedVersion: 3 diff --git a/Assets/Prefabs/ThrownGun.prefab b/Assets/Prefabs/ThrownGun.prefab index 050fde7..6814a98 100644 --- a/Assets/Prefabs/ThrownGun.prefab +++ b/Assets/Prefabs/ThrownGun.prefab @@ -28,13 +28,13 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 6611039685471789196} serializedVersion: 2 - m_LocalRotation: {x: 0.7071068, y: 0, z: 0, w: 0.7071068} + m_LocalRotation: {x: 0.38268343, y: 0, z: 0, w: 0.92387956} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 0.4, y: 0.5, z: 0.4} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 0} - m_LocalEulerAnglesHint: {x: 90, y: 0, z: 0} + m_LocalEulerAnglesHint: {x: 45, y: 0, z: 0} --- !u!33 &5688607449888095492 MeshFilter: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/GunThrown.cs b/Assets/Scripts/GunThrown.cs index 0119484..5affc78 100644 --- a/Assets/Scripts/GunThrown.cs +++ b/Assets/Scripts/GunThrown.cs @@ -4,6 +4,12 @@ public class GunThrown : MonoBehaviour { public GameObject player; public Vector3 TargetPosition; + + public Vector3 targetDirection; + public Quaternion targetRotation; + + public bool isStuck; + public float despawnTimer = 10; // Start is called once before the first execution of Update after the MonoBehaviour is created void Start() { @@ -14,12 +20,28 @@ public class GunThrown : MonoBehaviour // Update is called once per frame void Update() { + transform.LookAt(player.transform); + transform.rotation = Quaternion.Euler(transform.rotation.x + 55, transform.rotation.y, transform.rotation.z); transform.position = Vector3.MoveTowards(transform.position, TargetPosition, 10 * Time.deltaTime); + + if (transform.position == TargetPosition) + { + isStuck = true; + } + + if (isStuck) + { + despawnTimer -= Time.deltaTime; + if (despawnTimer <= 0) + { + Destroy(this.gameObject); + } + } } - private void OnCollisionEnter(Collision collision) + private void OnCollisionStay(Collision collision) { - if (collision.gameObject.tag == "Player") + if (collision.gameObject.tag == "Player" && !isStuck) { Destroy(this.gameObject); } diff --git a/Assets/Scripts/ThrowerEnemy.cs b/Assets/Scripts/ThrowerEnemy.cs index 131f83a..d835f96 100644 --- a/Assets/Scripts/ThrowerEnemy.cs +++ b/Assets/Scripts/ThrowerEnemy.cs @@ -53,7 +53,7 @@ public class ThrowerEnemy : MonoBehaviour playerDistance = Vector3.Distance(transform.position, target.position); if (playerDistance < 25 && canThrow) { - Instantiate(GunThrow, transform); + Instantiate(GunThrow, transform.position, Quaternion.identity); canThrow = false; } }