diff --git a/Assets/Scenes/Development/CharacterControllerTest.unity b/Assets/Scenes/Development/CharacterControllerTest.unity index e027715..0de0bad 100644 --- a/Assets/Scenes/Development/CharacterControllerTest.unity +++ b/Assets/Scenes/Development/CharacterControllerTest.unity @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:c3bc2d1abea8dfa233734dc9da271423c8ef68087f4aac8b2952baee7b8ba5ff -size 17564 +oid sha256:6e0cc9fb1eb2caf55429823d267246cb81ddc50428e94e872162198b0dac52e9 +size 19170 diff --git a/Assets/Scripts/Player/HandController.cs b/Assets/Scripts/Player/HandController.cs index 379ce18..7f9ef2c 100644 --- a/Assets/Scripts/Player/HandController.cs +++ b/Assets/Scripts/Player/HandController.cs @@ -16,7 +16,10 @@ public class HandController : MonoBehaviour [SerializeField, BoxGroup("References")] private Transform m_handTransform; - [SerializeField] + [SerializeField, BoxGroup("References")] + private OarController m_oar; + + [SerializeField,BoxGroup("settings")] private Transform m_otherHand; [SerializeField, BoxGroup("Settings")] @@ -27,9 +30,12 @@ public class HandController : MonoBehaviour [SerializeField, BoxGroup("Settings")] private float m_armRange = 1; - [SerializeField, BoxGroup("Settings"),Range(0.0f,1.0f)] + [SerializeField, BoxGroup("Settings"), Range(0.0f, 1.0f)] private float m_armSpeed = 0.5f; + [SerializeField, BoxGroup("Settings")] + private Vector2 m_startInput = new Vector2(0, 1); + [SerializeField, BoxGroup("Input")] private InputActionProperty m_inputAxis; @@ -47,6 +53,7 @@ public class HandController : MonoBehaviour private Vector3 m_startPosition; private Vector3 m_lastPosition; + private bool m_doUndo; #endregion Private Fields #region Getters @@ -59,7 +66,8 @@ public class HandController : MonoBehaviour private void Start() { - m_startPosition = transform.localPosition; + m_startPosition = transform.localPosition; + UpdateHand(m_startInput); } /// @@ -95,20 +103,21 @@ public class HandController : MonoBehaviour #endregion MonoBehaviour Functions #region Class Functionality - + /// /// Called every fixed update to move the arms /// /// - private void UpdateHand(Vector2 input) + private void UpdateHand(Vector2 input, bool registerUndo = true) { m_lastPosition = transform.localPosition; + + Quaternion rotation = Quaternion.LookRotation(m_axisForward.normalized, m_axisNormal.normalized); Vector3 axisInput = transform.rotation * rotation * new Vector3(input.x, 0, input.y); - Vector3 desiredPosition = m_startPosition + axisInput * m_armRange; transform.localPosition = Vector3.Lerp(transform.localPosition, desiredPosition, m_armSpeed); @@ -120,13 +129,15 @@ public class HandController : MonoBehaviour } } - } public void UndoLastMovement() { - transform.localPosition = m_lastPosition; + Vector3 direction = m_lastPosition - transform.localPosition; + + transform.localPosition += direction; + } @@ -136,8 +147,8 @@ public class HandController : MonoBehaviour /// private void OnInputRecieved(InputAction.CallbackContext args) { - - m_desiredInput = args.ReadValue(); + + m_desiredInput = args.ReadValue(); } @@ -150,7 +161,7 @@ public class HandController : MonoBehaviour private void Reset() { m_handTransform = base.transform; - } + } #endregion Editor Functions } \ No newline at end of file diff --git a/Assets/Scripts/Player/OarController.cs b/Assets/Scripts/Player/OarController.cs index 9a88996..6d4d589 100644 --- a/Assets/Scripts/Player/OarController.cs +++ b/Assets/Scripts/Player/OarController.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using UnityEngine; using NaughtyAttributes; +using TMPro; /// @@ -25,6 +26,9 @@ public class OarController : MonoBehaviour [SerializeField, BoxGroup("References")] private Transform m_body; + [SerializeField] + private BoxCollider m_boxCollider; + [SerializeField] private List m_forbiddenColliders; @@ -50,6 +54,7 @@ public class OarController : MonoBehaviour private void Awake() { + m_boxCollider.enabled= false; m_distanceFromRightHand = Vector3.Distance(m_rightHand.transform.position, transform.position); m_oarRigidbody = GetComponent(); } @@ -90,8 +95,41 @@ public class OarController : MonoBehaviour Vector3 forward = Vector3.Cross(direction, m_body.forward); Quaternion rotation = Quaternion.LookRotation(forward, direction); - m_oarRigidbody.MovePosition(m_rightHand.transform.position - direction * m_distanceFromRightHand); - m_oarRigidbody.MoveRotation(rotation); + + MoveOarToPosition(m_rightHand.transform.position - direction * m_distanceFromRightHand); + //m_oarRigidbody.MoveRotation(rotation); + //m_oarRigidbody.MovePosition(m_rightHand.transform.position - direction * m_distanceFromRightHand); + MoveOarToRotation(rotation); + + + } + + + private void MoveOarToPosition(Vector3 position) + { + m_oarRigidbody.velocity = (position - transform.position) * (1 / Time.fixedDeltaTime); + } + + private void MoveOarToRotation(Quaternion rotation) + { + Quaternion difference = rotation * Quaternion.Inverse(transform.rotation); + m_oarRigidbody.angularVelocity = (rotation.eulerAngles * Time.fixedDeltaTime); + } + + + public bool isColliding() + { + Vector3 direction = (m_rightHand.transform.position - m_leftHand.transform.position).normalized; + Vector3 forward = Vector3.Cross(direction, m_body.forward); + Quaternion rotation = Quaternion.LookRotation(forward, direction); + + Collider[] col = Physics.OverlapBox(transform.position + m_boxCollider.center, m_boxCollider.size / 2, rotation); + if (col.Intersect(m_forbiddenColliders).Any()) + { + Debug.Log($"Colliding with: {string.Join(", ", col.Intersect(m_forbiddenColliders))}"); + return true; + } + return false; } diff --git a/Assets/Scripts/Player/OarController.cs.meta b/Assets/Scripts/Player/OarController.cs.meta index c9338dd..5996629 100644 --- a/Assets/Scripts/Player/OarController.cs.meta +++ b/Assets/Scripts/Player/OarController.cs.meta @@ -4,7 +4,7 @@ MonoImporter: externalObjects: {} serializedVersion: 2 defaultReferences: [] - executionOrder: 0 + executionOrder: 100 icon: {instanceID: 0} userData: assetBundleName: diff --git a/Assets/Scripts/Player/RowController.cs b/Assets/Scripts/Player/RowController.cs index 245567f..61a897d 100644 --- a/Assets/Scripts/Player/RowController.cs +++ b/Assets/Scripts/Player/RowController.cs @@ -29,7 +29,7 @@ public class RowController : MonoBehaviour #endregion Inspector Fields #region Private Fields - + #endregion Private Fields #region Getters diff --git a/ProjectSettings/TagManager.asset b/ProjectSettings/TagManager.asset index 4b69f59..0c8c80b 100644 --- a/ProjectSettings/TagManager.asset +++ b/ProjectSettings/TagManager.asset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:8e18b1c820e9c09e16bbd1f1b7842e9fb3b0158a0921b0964e0b8fa12c6e2c01 -size 378 +oid sha256:28529725e71fa58fdb2277e07306508472f8b936b0c5a6b386c90f1f4d415453 +size 390