Skip to content

Commit

Permalink
improve item hit point
Browse files Browse the repository at this point in the history
  • Loading branch information
stilnat committed Oct 28, 2024
1 parent 8881e86 commit 1c3ec07
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -286,7 +286,7 @@ private Vector3 ComputeTargetHandHoldPosition(IHoldProvider holdable, Vector3 fr

ItemHitPoint hitPoint = _hands.SelectedHand.ItemInHand.GetComponent<ItemHitPoint>();

item.rotation = QuaternionExtension.AltForwardLookRotation(item.GetComponent<ItemHitPoint>().HitPoint.forward, hitPoint.forwardHit, hitPoint.upHit);
item.rotation = QuaternionExtension.AltForwardLookRotation(item.GetComponent<ItemHitPoint>().HitPoint.forward, hitPoint.ForwardHit, hitPoint.UpHit);

// Place item such that the item hit position match the target hit position
item.position = targetHitPosition - item.GetComponent<ItemHitPoint>().HitPoint.localPosition;
Expand Down
32 changes: 29 additions & 3 deletions Assets/Scripts/SS3D/Systems/Animations/ItemHitPoint.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,40 @@
using NaughtyAttributes;
using System.Collections.Generic;
using UnityEngine;

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<Vector3> GetDirectionValues()
{
return new DropdownList<Vector3>()
{
{ "Right", Vector3.right },
{ "Left", Vector3.left },
{ "Up", Vector3.up },
{ "Down", Vector3.down },
{ "Forward", Vector3.forward },
{ "Back", Vector3.back },
};
}
}
}

0 comments on commit 1c3ec07

Please sign in to comment.