Jordan 1 year ago
parent
commit
925a10414d
12 changed files with 165 additions and 46 deletions
  1. BIN
      Assets/Scenes/BoatTest.unity
  2. BIN
      Assets/Scenes/Development/CharacterControllerTest.unity
  3. +8
    -0
      Assets/Scenes/Utility.meta
  4. +87
    -0
      Assets/Scenes/Utility/CopyTransform.cs
  5. +11
    -0
      Assets/Scenes/Utility/CopyTransform.cs.meta
  6. +7
    -1
      Assets/Scripts/BoatController.cs
  7. +28
    -10
      Assets/Scripts/Player/BoatRowController.cs
  8. +1
    -1
      Assets/Scripts/Player/HandController.cs
  9. +7
    -21
      Assets/Scripts/Player/OarController.cs
  10. +9
    -6
      Assets/Scripts/Player/PlayerController.cs
  11. BIN
      ProjectSettings/DynamicsManager.asset
  12. BIN
      ProjectSettings/TagManager.asset

BIN
Assets/Scenes/BoatTest.unity (Stored with Git LFS) View File

size 73717

BIN
Assets/Scenes/Development/CharacterControllerTest.unity (Stored with Git LFS) View File

size 8513

+ 8
- 0
Assets/Scenes/Utility.meta View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f29057d258e1d49459df24e6862140e7
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

+ 87
- 0
Assets/Scenes/Utility/CopyTransform.cs View File

@ -0,0 +1,87 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using NaughtyAttributes;
/// <summary>
/// Utility script to fake parent an object to another
/// </summary>
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);
}
/// <summary>
/// OnEnable is called when the object becomes enabled and active.
/// </summary>
private void OnEnable()
{
}
/// <summary>
/// OnDisable is called when the behaviour becomes disabled.
/// </summary>
private void OnDisable()
{
}
/// <summary>
/// Update is called once per frame
/// </summary>
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
/// <summary>
/// Called when the Component is created or Reset from the Inspector
/// </summary>
private void Reset()
{
//useful for finding components on creation
}
#endregion Editor Functions
}

+ 11
- 0
Assets/Scenes/Utility/CopyTransform.cs.meta View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 402a55c05df6014479f29432c30e3873
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

+ 7
- 1
Assets/Scripts/BoatController.cs View File

@ -13,6 +13,9 @@ public class BoatController : MonoBehaviour
[SerializeField]
private float BrakeFactor = 1f;
[SerializeField]
private bool m_usedebugkeys;
void Awake()
{
rigidBody = GetComponent<Rigidbody>();
@ -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)
{

+ 28
- 10
Assets/Scripts/Player/BoatRowController.cs View File

@ -2,7 +2,8 @@ using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using NaughtyAttributes;
using Unity.VisualScripting;
using UnityEngine.Events;
/// <summary>
///
@ -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,21 +57,38 @@ public class BoatRowController : MonoBehaviour
private void OnTriggerEnter(Collider other)
{
if(other == m_oar)
OarController oar = other.GetComponentInParent<OarController>();
if (oar != null)
{
m_lastKnownOarPosition = m_oarTip.position;
m_lastKnownOarPosition = m_oarTip.localPosition;
}
}
void OnTriggerStay(Collider other)
{
if(other == m_oar)
OarController oar = other.GetComponentInParent<OarController>();
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,Vector3.forward);
if (directionality > 0)
{
Debug.Log($"Row! ({directionality})");
m_OnRow.Invoke();
}
else
{
Debug.Log($"No Row: {directionality}");
}
m_lastKnownOarPosition=m_oarTip.localPosition;
}
else
{
Debug.Log($"Not Oar: {other.gameObject}");
}
}

+ 1
- 1
Assets/Scripts/Player/HandController.cs View File

@ -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);

+ 7
- 21
Assets/Scripts/Player/OarController.cs View File

@ -99,8 +99,8 @@ public class OarController : MonoBehaviour
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,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

+ 9
- 6
Assets/Scripts/Player/PlayerController.cs View File

@ -36,7 +36,7 @@ public class PlayerController : MonoBehaviour
/// </summary>
private void OnEnable()
{
rightHand.UpdateHand(Vector2.up);
}
/// <summary>
@ -52,17 +52,20 @@ public class PlayerController : MonoBehaviour
/// </summary>
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

BIN
ProjectSettings/DynamicsManager.asset (Stored with Git LFS) View File

size 1323

BIN
ProjectSettings/TagManager.asset (Stored with Git LFS) View File

size 394

Loading…
Cancel
Save