From 1c3ec077a948d840563a45df6bd8bace96db584e Mon Sep 17 00:00:00 2001 From: stilnat Date: Mon, 28 Oct 2024 19:21:44 +0100 Subject: [PATCH] improve item hit point --- .../Objects/ToolBoxes/ToolboxBlue.prefab | 6 ++-- .../Tools/Engineering/Wrench.prefab | 6 ++-- .../Animations/HitWithItemAnimation.cs | 6 ++-- .../SS3D/Systems/Animations/ItemHitPoint.cs | 32 +++++++++++++++++-- 4 files changed, 38 insertions(+), 12 deletions(-) diff --git a/Assets/Content/WorldObjects/Items/Functional/Storage/Objects/ToolBoxes/ToolboxBlue.prefab b/Assets/Content/WorldObjects/Items/Functional/Storage/Objects/ToolBoxes/ToolboxBlue.prefab index 0cc8d8d4a..ae1a49d9a 100644 --- a/Assets/Content/WorldObjects/Items/Functional/Storage/Objects/ToolBoxes/ToolboxBlue.prefab +++ b/Assets/Content/WorldObjects/Items/Functional/Storage/Objects/ToolBoxes/ToolboxBlue.prefab @@ -504,9 +504,9 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 2106a18e55486ca4c9b0c7e41128f9b5, type: 3} m_Name: m_EditorClassIdentifier: - HitPoint: {fileID: 8004082369185482690} - forwardHit: {x: 0, y: 0, z: -1} - upHit: {x: 1, y: 0, z: 0} + _forwardHit: {x: 0, y: -1, z: 0} + _upHit: {x: 0, y: 0, z: -1} + _hitPoint: {fileID: 8004082369185482690} --- !u!1 &8783882920935154563 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Content/WorldObjects/Items/Functional/Tools/Engineering/Wrench.prefab b/Assets/Content/WorldObjects/Items/Functional/Tools/Engineering/Wrench.prefab index d2b1de644..d7e871f3c 100644 --- a/Assets/Content/WorldObjects/Items/Functional/Tools/Engineering/Wrench.prefab +++ b/Assets/Content/WorldObjects/Items/Functional/Tools/Engineering/Wrench.prefab @@ -332,9 +332,9 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 2106a18e55486ca4c9b0c7e41128f9b5, type: 3} m_Name: m_EditorClassIdentifier: - HitPoint: {fileID: 3424821083880257427} - forwardHit: {x: 0, y: 1, z: 0} - upHit: {x: 0, y: 0, z: -1} + _forwardHit: {x: 0, y: 1, z: 0} + _upHit: {x: 0, y: -1, z: 0} + _hitPoint: {fileID: 3424821083880257427} --- !u!1 &7767416049704309750 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/SS3D/Systems/Animations/HitWithItemAnimation.cs b/Assets/Scripts/SS3D/Systems/Animations/HitWithItemAnimation.cs index ce69dcd14..3d7f102ca 100644 --- a/Assets/Scripts/SS3D/Systems/Animations/HitWithItemAnimation.cs +++ b/Assets/Scripts/SS3D/Systems/Animations/HitWithItemAnimation.cs @@ -155,10 +155,10 @@ private Tween AnimateHandRotation(Vector3 hitTargetPosition, float duration, Qua Vector3 right = Vector3.Cross(Vector3.up, fromHandToHit).normalized; // the first rotation is such that the item is a bit toward the exterior to simulate gaining momentum - Quaternion firstRotation = QuaternionExtension.AltForwardLookRotation(-right + (0.5f * fromHandToHit), hitPoint.forwardHit, hitPoint.upHit); + Quaternion firstRotation = QuaternionExtension.AltForwardLookRotation(-right + (0.5f * fromHandToHit), hitPoint.ForwardHit, hitPoint.UpHit); // the last rotation is such that the item went a bit over the target rotation to simulate the momentum and rotation of arm - Quaternion lastRotation = QuaternionExtension.AltForwardLookRotation(right + fromHandToHit, hitPoint.forwardHit, hitPoint.upHit); + Quaternion lastRotation = QuaternionExtension.AltForwardLookRotation(right + fromHandToHit, hitPoint.ForwardHit, hitPoint.UpHit); rotation.Join(temp.transform.DORotate(firstRotation.eulerAngles, duration/2)); rotation.Append(temp.transform.DORotate(lastRotation.eulerAngles, duration/2)); @@ -286,7 +286,7 @@ private Vector3 ComputeTargetHandHoldPosition(IHoldProvider holdable, Vector3 fr ItemHitPoint hitPoint = _hands.SelectedHand.ItemInHand.GetComponent(); - item.rotation = QuaternionExtension.AltForwardLookRotation(item.GetComponent().HitPoint.forward, hitPoint.forwardHit, hitPoint.upHit); + item.rotation = QuaternionExtension.AltForwardLookRotation(item.GetComponent().HitPoint.forward, hitPoint.ForwardHit, hitPoint.UpHit); // Place item such that the item hit position match the target hit position item.position = targetHitPosition - item.GetComponent().HitPoint.localPosition; diff --git a/Assets/Scripts/SS3D/Systems/Animations/ItemHitPoint.cs b/Assets/Scripts/SS3D/Systems/Animations/ItemHitPoint.cs index e7ebc4f65..6f548130f 100644 --- a/Assets/Scripts/SS3D/Systems/Animations/ItemHitPoint.cs +++ b/Assets/Scripts/SS3D/Systems/Animations/ItemHitPoint.cs @@ -1,3 +1,5 @@ +using NaughtyAttributes; +using System.Collections.Generic; using UnityEngine; namespace SS3D.Systems.Animations @@ -5,10 +7,34 @@ namespace SS3D.Systems.Animations public class ItemHitPoint : MonoBehaviour { - public Transform HitPoint; + [SerializeField] + [Dropdown(nameof(GetDirectionValues))] + private Vector3 _forwardHit = Vector3.forward; - public Vector3 forwardHit = Vector3.forward; + [SerializeField] + [Dropdown(nameof(GetDirectionValues))] + private Vector3 _upHit = Vector3.up; - public Vector3 upHit = Vector3.up; + [SerializeField] + private Transform _hitPoint; + + public Transform HitPoint => _hitPoint; + + public Vector3 ForwardHit => _forwardHit; + + public Vector3 UpHit => _upHit; + + private DropdownList GetDirectionValues() + { + return new DropdownList() + { + { "Right", Vector3.right }, + { "Left", Vector3.left }, + { "Up", Vector3.up }, + { "Down", Vector3.down }, + { "Forward", Vector3.forward }, + { "Back", Vector3.back }, + }; + } } }