From 08591e5f1f354f233d5bc79293d3145514b6dd1e Mon Sep 17 00:00:00 2001 From: Joshua Reason Date: Sun, 5 Feb 2023 11:59:20 +1100 Subject: [PATCH 1/3] Starting working on combining boat and oar --- Assets/Scenes/BoatTest.unity | 4 +- .../Development/CharacterControllerTest.unity | 4 +- Assets/Scenes/Utility.meta | 8 ++ Assets/Scenes/Utility/CopyTransform.cs | 87 +++++++++++++++++++ Assets/Scenes/Utility/CopyTransform.cs.meta | 11 +++ Assets/Scripts/BoatController.cs | 8 +- Assets/Scripts/Player/BoatRowController.cs | 31 +++++-- Assets/Scripts/Player/OarController.cs | 28 ++---- Assets/Scripts/Player/PlayerController.cs | 15 ++-- ProjectSettings/DynamicsManager.asset | 2 +- ProjectSettings/TagManager.asset | 4 +- 11 files changed, 161 insertions(+), 41 deletions(-) create mode 100644 Assets/Scenes/Utility.meta create mode 100644 Assets/Scenes/Utility/CopyTransform.cs create mode 100644 Assets/Scenes/Utility/CopyTransform.cs.meta diff --git a/Assets/Scenes/BoatTest.unity b/Assets/Scenes/BoatTest.unity index 585a17e..9358a43 100644 --- a/Assets/Scenes/BoatTest.unity +++ b/Assets/Scenes/BoatTest.unity @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:51c8759d1d74c0e958bb8df7ddfd88a5e93a301bf4e288b3bd02954940af9ae5 -size 47470 +oid sha256:158ac3952298588515fa35a0745bc6f11a9742fd518cc57c6a55c1aebe060ce9 +size 71134 diff --git a/Assets/Scenes/Development/CharacterControllerTest.unity b/Assets/Scenes/Development/CharacterControllerTest.unity index bb4166a..c8f91d9 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:0a34ad1f5f427168262f727710e42c70ece3e600a53b591e39835d2c425d426a -size 21726 +oid sha256:24894f68749013207500f5f502e5ef2753c5be9a2b2b74009445948336e95510 +size 8513 diff --git a/Assets/Scenes/Utility.meta b/Assets/Scenes/Utility.meta new file mode 100644 index 0000000..9385599 --- /dev/null +++ b/Assets/Scenes/Utility.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: f29057d258e1d49459df24e6862140e7 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scenes/Utility/CopyTransform.cs b/Assets/Scenes/Utility/CopyTransform.cs new file mode 100644 index 0000000..d625d03 --- /dev/null +++ b/Assets/Scenes/Utility/CopyTransform.cs @@ -0,0 +1,87 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using NaughtyAttributes; + + +/// +/// Utility script to fake parent an object to another +/// +public class CopyTransform : MonoBehaviour +{ + + #region Inspector Fields + [SerializeField, BoxGroup("References")] + public Transform m_target; + + [SerializeField, Range(0, 1)] + public float m_dampening = 1; + #endregion Inspector Fields + + #region Private Fields + + private Vector3 m_positionOffset; + private Quaternion m_rotationOffset; + + + #endregion Private Fields + + #region Getters + + #endregion Getters + + + + #region MonoBehaviour Functions + + private void Awake() + { + m_positionOffset = transform.position - m_target.position; + m_rotationOffset = m_target.rotation * Quaternion.Inverse(transform.rotation); + } + + /// + /// OnEnable is called when the object becomes enabled and active. + /// + private void OnEnable() + { + + } + + /// + /// OnDisable is called when the behaviour becomes disabled. + /// + private void OnDisable() + { + + } + + /// + /// Update is called once per frame + /// + private void FixedUpdate() + { + Vector3 expectedPosition = m_target.position + (m_target.rotation * m_positionOffset); + Quaternion expectedRotation = m_target.rotation * m_rotationOffset; + + transform.position = Vector3.Lerp(transform.position, expectedPosition, m_dampening); + transform.rotation = Quaternion.Lerp(transform.rotation, expectedRotation, m_dampening); + } + + #endregion MonoBehaviour Functions + + #region Class Functionality + + #endregion Class Functionality + + #region Editor Functions + /// + /// Called when the Component is created or Reset from the Inspector + /// + private void Reset() + { + //useful for finding components on creation + } + #endregion Editor Functions + +} \ No newline at end of file diff --git a/Assets/Scenes/Utility/CopyTransform.cs.meta b/Assets/Scenes/Utility/CopyTransform.cs.meta new file mode 100644 index 0000000..614532a --- /dev/null +++ b/Assets/Scenes/Utility/CopyTransform.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 402a55c05df6014479f29432c30e3873 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/BoatController.cs b/Assets/Scripts/BoatController.cs index 6fe2c01..65a9423 100644 --- a/Assets/Scripts/BoatController.cs +++ b/Assets/Scripts/BoatController.cs @@ -13,6 +13,9 @@ public class BoatController : MonoBehaviour [SerializeField] private float BrakeFactor = 1f; + [SerializeField] + private bool m_usedebugkeys; + void Awake() { rigidBody = GetComponent(); @@ -21,6 +24,9 @@ public class BoatController : MonoBehaviour // Update is called once per frame void Update() { + if (!m_usedebugkeys) + return; + //get input if (Input.GetKeyDown(KeyCode.A)) { @@ -38,7 +44,7 @@ public class BoatController : MonoBehaviour private void FixedUpdate() { - print(transform.rotation.eulerAngles.y); + //print(transform.rotation.eulerAngles.y); //constrain rotation if (transform.rotation.eulerAngles.y > 180 && transform.rotation.eulerAngles.y < 270) { diff --git a/Assets/Scripts/Player/BoatRowController.cs b/Assets/Scripts/Player/BoatRowController.cs index 33f0c18..d316f06 100644 --- a/Assets/Scripts/Player/BoatRowController.cs +++ b/Assets/Scripts/Player/BoatRowController.cs @@ -2,7 +2,8 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; using NaughtyAttributes; - +using Unity.VisualScripting; +using UnityEngine.Events; /// /// @@ -11,8 +12,8 @@ public class BoatRowController : MonoBehaviour { #region Inspector Fields - public Collider m_oar; public Transform m_oarTip; + public UnityEvent m_OnRow; #endregion Inspector Fields #region Private Fields @@ -56,7 +57,8 @@ public class BoatRowController : MonoBehaviour private void OnTriggerEnter(Collider other) { - if(other == m_oar) + OarController oar = other.GetComponentInParent(); + if (oar != null) { m_lastKnownOarPosition = m_oarTip.position; } @@ -64,13 +66,30 @@ public class BoatRowController : MonoBehaviour void OnTriggerStay(Collider other) { - if(other == m_oar) + OarController oar = other.GetComponentInParent(); + if(oar != null) { Vector3 direction = m_lastKnownOarPosition - m_oarTip.position; direction = Vector3.Project(direction,transform.forward); - - } + float directionality = Vector3.Dot(direction,transform.forward); + + if (directionality > 0) + { + // Debug.Log($"Row! ({directionality})"); + m_OnRow.Invoke(); + } + else + { + // Debug.Log($"No Row: {directionality}"); + } + m_lastKnownOarPosition=m_oarTip.position; + } + else + { + // Debug.Log($"Not Oar: {other.gameObject}"); + } + } diff --git a/Assets/Scripts/Player/OarController.cs b/Assets/Scripts/Player/OarController.cs index af87e89..efa9b23 100644 --- a/Assets/Scripts/Player/OarController.cs +++ b/Assets/Scripts/Player/OarController.cs @@ -96,8 +96,8 @@ public class OarController : MonoBehaviour Quaternion rotation = Quaternion.LookRotation(forward, direction); - transform.rotation = rotation; - transform.position = m_rightHand.transform.position - direction * m_distanceFromRightHand; + //transform.rotation = rotation; + //transform.position = m_rightHand.transform.position - direction * m_distanceFromRightHand; //MoveOarToPosition(m_rightHand.transform.position - direction * m_distanceFromRightHand); m_oarRigidbody.MoveRotation(rotation); m_oarRigidbody.MovePosition(m_rightHand.transform.position - direction * m_distanceFromRightHand); @@ -128,33 +128,19 @@ public class OarController : MonoBehaviour Collider[] col = Physics.OverlapBox(transform.position + m_boxCollider.center, m_boxCollider.size / 2, rotation); if (col.Intersect(m_forbiddenColliders).Any()) { - + Debug.Log($"Forbidden collision: {string.Join(", ", col.Intersect(m_forbiddenColliders))}"); return true; } - return false; - - - } - -/* - void OnCollisionEnter(Collision collision) - { - - if (m_forbiddenColliders.Contains(collision.collider) && !undoDoneThisFrame) - { - Debug.Log($"Forbidden Collision: {collision.collider.gameObject}"); - undoDoneThisFrame= true; - m_leftHand.UndoLastMovement(); - m_rightHand.UndoLastMovement(); - } else { - Debug.Log($"Ignored Collision: {collision.collider.gameObject}"); + Debug.Log($"Ignored collision: {string.Join(", ", col.Except(m_forbiddenColliders))}"); } + return false; + } + - }*/ #endregion Class Functionality diff --git a/Assets/Scripts/Player/PlayerController.cs b/Assets/Scripts/Player/PlayerController.cs index d86929c..9f17d39 100644 --- a/Assets/Scripts/Player/PlayerController.cs +++ b/Assets/Scripts/Player/PlayerController.cs @@ -36,7 +36,7 @@ public class PlayerController : MonoBehaviour /// private void OnEnable() { - + rightHand.UpdateHand(Vector2.up); } /// @@ -52,17 +52,20 @@ public class PlayerController : MonoBehaviour /// private void FixedUpdate() { - leftHand.UpdateHand(leftHand.m_desiredInput); - rightHand.UpdateHand(rightHand.m_desiredInput); - - oar.UpdateTransform(); if (oar.isColliding()) { leftHand.UndoLastMovement(); rightHand.UndoLastMovement(); - + oar.UpdateTransform(); } + + leftHand.UpdateHand(leftHand.m_desiredInput); + rightHand.UpdateHand(rightHand.m_desiredInput); + + oar.UpdateTransform(); + + } #endregion MonoBehaviour Functions diff --git a/ProjectSettings/DynamicsManager.asset b/ProjectSettings/DynamicsManager.asset index 6827b69..82cb6a6 100644 --- a/ProjectSettings/DynamicsManager.asset +++ b/ProjectSettings/DynamicsManager.asset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:c180f985770287728278a4dc939c76a04d76b519697ff906c33d202fd44e1a1e +oid sha256:26dcf28468677832b76ff313e6c988e4a24bf42d3d7103a86964843d265f582a size 1323 diff --git a/ProjectSettings/TagManager.asset b/ProjectSettings/TagManager.asset index 0c8c80b..6e981f6 100644 --- a/ProjectSettings/TagManager.asset +++ b/ProjectSettings/TagManager.asset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:28529725e71fa58fdb2277e07306508472f8b936b0c5a6b386c90f1f4d415453 -size 390 +oid sha256:257adc2e17b69e053a710c5d8e6a52820e964684ee546ec36f9411e1609b7055 +size 394 From c563d517705ce804b0820a7b56b60571d46ac9a2 Mon Sep 17 00:00:00 2001 From: Joshua Reason Date: Sun, 5 Feb 2023 12:35:07 +1100 Subject: [PATCH 2/3] oar mechanichs --- Assets/Scripts/Player/BoatRowController.cs | 15 +++++++-------- Assets/Scripts/Player/HandController.cs | 2 +- Assets/Scripts/Player/OarController.cs | 12 ++++++------ 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/Assets/Scripts/Player/BoatRowController.cs b/Assets/Scripts/Player/BoatRowController.cs index d316f06..b496617 100644 --- a/Assets/Scripts/Player/BoatRowController.cs +++ b/Assets/Scripts/Player/BoatRowController.cs @@ -60,7 +60,7 @@ public class BoatRowController : MonoBehaviour OarController oar = other.GetComponentInParent(); if (oar != null) { - m_lastKnownOarPosition = m_oarTip.position; + m_lastKnownOarPosition = m_oarTip.localPosition; } } @@ -69,25 +69,24 @@ public class BoatRowController : MonoBehaviour OarController oar = other.GetComponentInParent(); if(oar != null) { - Vector3 direction = m_lastKnownOarPosition - m_oarTip.position; - direction = Vector3.Project(direction,transform.forward); + Vector3 direction = m_lastKnownOarPosition - m_oarTip.localPosition; - float directionality = Vector3.Dot(direction,transform.forward); + float directionality = Vector3.Dot(direction,Vector3.forward); if (directionality > 0) { - // Debug.Log($"Row! ({directionality})"); + Debug.Log($"Row! ({directionality})"); m_OnRow.Invoke(); } else { - // Debug.Log($"No Row: {directionality}"); + Debug.Log($"No Row: {directionality}"); } - m_lastKnownOarPosition=m_oarTip.position; + m_lastKnownOarPosition=m_oarTip.localPosition; } else { - // Debug.Log($"Not Oar: {other.gameObject}"); + Debug.Log($"Not Oar: {other.gameObject}"); } } diff --git a/Assets/Scripts/Player/HandController.cs b/Assets/Scripts/Player/HandController.cs index f8f7aa6..c2d130f 100644 --- a/Assets/Scripts/Player/HandController.cs +++ b/Assets/Scripts/Player/HandController.cs @@ -116,7 +116,7 @@ public class HandController : MonoBehaviour Quaternion rotation = Quaternion.LookRotation(m_axisForward.normalized, m_axisNormal.normalized); - Vector3 axisInput = transform.rotation * rotation * new Vector3(input.x, 0, input.y); + Vector3 axisInput = rotation * new Vector3(input.x, 0, input.y); Vector3 desiredPosition = m_startPosition + axisInput * m_armRange; transform.localPosition = Vector3.Lerp(transform.localPosition, desiredPosition, m_armSpeed); diff --git a/Assets/Scripts/Player/OarController.cs b/Assets/Scripts/Player/OarController.cs index efa9b23..3466863 100644 --- a/Assets/Scripts/Player/OarController.cs +++ b/Assets/Scripts/Player/OarController.cs @@ -96,11 +96,11 @@ public class OarController : MonoBehaviour Quaternion rotation = Quaternion.LookRotation(forward, direction); - //transform.rotation = rotation; - //transform.position = m_rightHand.transform.position - direction * m_distanceFromRightHand; + transform.rotation = rotation; + transform.position = m_rightHand.transform.position - direction * m_distanceFromRightHand; //MoveOarToPosition(m_rightHand.transform.position - direction * m_distanceFromRightHand); - m_oarRigidbody.MoveRotation(rotation); - m_oarRigidbody.MovePosition(m_rightHand.transform.position - direction * m_distanceFromRightHand); + //m_oarRigidbody.MoveRotation(rotation); + //m_oarRigidbody.MovePosition(m_rightHand.transform.position - direction * m_distanceFromRightHand); //MoveOarToRotation(rotation); @@ -128,12 +128,12 @@ public class OarController : MonoBehaviour Collider[] col = Physics.OverlapBox(transform.position + m_boxCollider.center, m_boxCollider.size / 2, rotation); if (col.Intersect(m_forbiddenColliders).Any()) { - Debug.Log($"Forbidden collision: {string.Join(", ", col.Intersect(m_forbiddenColliders))}"); + //Debug.Log($"Forbidden collision: {string.Join(", ", col.Intersect(m_forbiddenColliders))}"); return true; } else { - Debug.Log($"Ignored collision: {string.Join(", ", col.Except(m_forbiddenColliders))}"); + // Debug.Log($"Ignored collision: {string.Join(", ", col.Except(m_forbiddenColliders))}"); } return false; From df5a2ff4166226b8e4b7571a6da798d2480062fb Mon Sep 17 00:00:00 2001 From: Joshua Reason Date: Sun, 5 Feb 2023 13:30:03 +1100 Subject: [PATCH 3/3] saved boat scene --- Assets/Scenes/BoatTest.unity | 4 ++-- ProjectSettings/DynamicsManager.asset | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Assets/Scenes/BoatTest.unity b/Assets/Scenes/BoatTest.unity index 9358a43..c049596 100644 --- a/Assets/Scenes/BoatTest.unity +++ b/Assets/Scenes/BoatTest.unity @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:158ac3952298588515fa35a0745bc6f11a9742fd518cc57c6a55c1aebe060ce9 -size 71134 +oid sha256:4d0ec36d9b37bf7a9f684f834da6ee33b8b7a939bdbe265adf551380dfce347f +size 73717 diff --git a/ProjectSettings/DynamicsManager.asset b/ProjectSettings/DynamicsManager.asset index 82cb6a6..0d97b04 100644 --- a/ProjectSettings/DynamicsManager.asset +++ b/ProjectSettings/DynamicsManager.asset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:26dcf28468677832b76ff313e6c988e4a24bf42d3d7103a86964843d265f582a +oid sha256:e127c9b4d8872ac4c7ae7092ef6f2120283433c01c397e1a3344c2f851a4d1f6 size 1323