Joshua 1 year ago
parent
commit
b8013873da
6 changed files with 68 additions and 19 deletions
  1. BIN
      Assets/Scenes/Development/CharacterControllerTest.unity
  2. +22
    -11
      Assets/Scripts/Player/HandController.cs
  3. +40
    -2
      Assets/Scripts/Player/OarController.cs
  4. +1
    -1
      Assets/Scripts/Player/OarController.cs.meta
  5. +1
    -1
      Assets/Scripts/Player/RowController.cs
  6. BIN
      ProjectSettings/TagManager.asset

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

size 19170

+ 22
- 11
Assets/Scripts/Player/HandController.cs View File

@ -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);
}
/// <summary>
@ -95,20 +103,21 @@ public class HandController : MonoBehaviour
#endregion MonoBehaviour Functions
#region Class Functionality
/// <summary>
/// Called every fixed update to move the arms
/// </summary>
/// <param name="input"></param>
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
/// <param name="args"></param>
private void OnInputRecieved(InputAction.CallbackContext args)
{
m_desiredInput = args.ReadValue<Vector2>();
m_desiredInput = args.ReadValue<Vector2>();
}
@ -150,7 +161,7 @@ public class HandController : MonoBehaviour
private void Reset()
{
m_handTransform = base.transform;
}
}
#endregion Editor Functions
}

+ 40
- 2
Assets/Scripts/Player/OarController.cs View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using NaughtyAttributes;
using TMPro;
/// <summary>
@ -25,6 +26,9 @@ public class OarController : MonoBehaviour
[SerializeField, BoxGroup("References")]
private Transform m_body;
[SerializeField]
private BoxCollider m_boxCollider;
[SerializeField]
private List<Collider> 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<Rigidbody>();
}
@ -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;
}

+ 1
- 1
Assets/Scripts/Player/OarController.cs.meta View File

@ -4,7 +4,7 @@ MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
executionOrder: 100
icon: {instanceID: 0}
userData:
assetBundleName:

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

@ -29,7 +29,7 @@ public class RowController : MonoBehaviour
#endregion Inspector Fields
#region Private Fields
#endregion Private Fields
#region Getters

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

size 390

Loading…
Cancel
Save