Browse Source

working oar

feature/routeTiling^2
Joshua Reason 1 year ago
parent
commit
09d913e14f
13 changed files with 1457 additions and 8 deletions
  1. BIN
      Assets/Prefab/Player.prefab
  2. +7
    -0
      Assets/Prefab/Player.prefab.meta
  3. +8
    -0
      Assets/Scenes/Development.meta
  4. BIN
      Assets/Scenes/Development/CharacterControllerTest.unity
  5. +7
    -0
      Assets/Scenes/Development/CharacterControllerTest.unity.meta
  6. +156
    -0
      Assets/Scripts/Player/HandController.cs
  7. +11
    -0
      Assets/Scripts/Player/HandController.cs.meta
  8. +119
    -6
      Assets/Scripts/Player/OarController.cs
  9. +86
    -0
      Assets/Scripts/Player/RowController.cs
  10. +11
    -0
      Assets/Scripts/Player/RowController.cs.meta
  11. +1030
    -0
      Assets/Settings/PlayerInput.inputactions
  12. +14
    -0
      Assets/Settings/PlayerInput.inputactions.meta
  13. BIN
      ProjectSettings/DynamicsManager.asset

BIN
Assets/Prefab/Player.prefab (Stored with Git LFS) View File

size 21839

+ 7
- 0
Assets/Prefab/Player.prefab.meta View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 72514749158858a4e8977db04e36b05a
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

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

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

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

size 17564

+ 7
- 0
Assets/Scenes/Development/CharacterControllerTest.unity.meta View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 08c61a126f535e24592d442f7d72b045
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

+ 156
- 0
Assets/Scripts/Player/HandController.cs View File

@ -0,0 +1,156 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
using NaughtyAttributes;
/// <summary>
///
/// </summary>
public class HandController : MonoBehaviour
{
#region Inspector Fields
[SerializeField, BoxGroup("References")]
private Transform m_handTransform;
[SerializeField]
private Transform m_otherHand;
[SerializeField, BoxGroup("Settings")]
private Vector3 m_axisNormal = Vector3.forward;
[SerializeField, BoxGroup("Settings")]
private Vector3 m_axisForward = Vector3.up;
[SerializeField, BoxGroup("Settings")]
private float m_armRange = 1;
[SerializeField, BoxGroup("Settings"),Range(0.0f,1.0f)]
private float m_armSpeed = 0.5f;
[SerializeField, BoxGroup("Input")]
private InputActionProperty m_inputAxis;
[SerializeField, BoxGroup("Input")]
private InputActionProperty m_row;
#endregion Inspector Fields
#region Private Fields
//Last input of player
private Vector2 m_desiredInput;
private Vector3 m_startPosition;
private Vector3 m_lastPosition;
#endregion Private Fields
#region Getters
public new Transform transform => m_handTransform;
#endregion Getters
#region MonoBehaviour Functions
private void Start()
{
m_startPosition = transform.localPosition;
}
/// <summary>
/// OnEnable is called when the object becomes enabled and active.
/// </summary>
private void OnEnable()
{
m_inputAxis.action.performed += OnInputRecieved;
m_inputAxis.action.canceled += OnInputRecieved;
m_inputAxis.action.Enable();
m_row.action?.Enable();
}
/// <summary>
/// OnDisable is called when the behaviour becomes disabled.
/// </summary>
private void OnDisable()
{
m_inputAxis.action.performed -= OnInputRecieved;
m_inputAxis.action.canceled -= OnInputRecieved;
m_inputAxis.action.Disable();
m_row.action?.Disable();
}
/// <summary>
/// Update is called once per frame
/// </summary>
private void FixedUpdate()
{
UpdateHand(m_desiredInput);
}
#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)
{
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);
if (m_row.action != null)
{
if (m_row.action.IsPressed())
{
transform.localPosition = Vector3.Lerp(transform.localPosition, m_otherHand.localPosition, 0.5f);
}
}
}
public void UndoLastMovement()
{
transform.localPosition = m_lastPosition;
}
/// <summary>
/// Called by the input system when the input is changed
/// </summary>
/// <param name="args"></param>
private void OnInputRecieved(InputAction.CallbackContext args)
{
m_desiredInput = args.ReadValue<Vector2>();
}
#endregion Class Functionality
#region Editor Functions
/// <summary>
/// Called when the Component is created or Reset from the Inspector
/// </summary>
private void Reset()
{
m_handTransform = base.transform;
}
#endregion Editor Functions
}

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

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

+ 119
- 6
Assets/Scripts/Player/OarController.cs View File

@ -1,18 +1,131 @@
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using UnityEngine; using UnityEngine;
using NaughtyAttributes;
/// <summary>
/// Script to control player input and oars
/// </summary>
public class OarController : MonoBehaviour public class OarController : MonoBehaviour
{ {
// Start is called before the first frame update
void Start()
#region Inspector Fields
[SerializeField,BoxGroup("References")]
private HandController m_leftHand;
[SerializeField, BoxGroup("References")]
private HandController m_rightHand;
[SerializeField, BoxGroup("References")]
private Rigidbody m_oarRigidbody;
[SerializeField, BoxGroup("References")]
private Transform m_body;
[SerializeField]
private List<Collider> m_forbiddenColliders;
#endregion Inspector Fields
#region Private Fields
float m_distanceFromRightHand;
bool undoDoneThisFrame = false;
#endregion Private Fields
#region Getters
public new Transform transform => m_oarRigidbody.transform;
#endregion Getters
#region MonoBehaviour Functions
private void Awake()
{ {
m_distanceFromRightHand = Vector3.Distance(m_rightHand.transform.position, transform.position);
m_oarRigidbody = GetComponent<Rigidbody>();
}
/// <summary>
/// OnEnable is called when the object becomes enabled and active.
/// </summary>
private void OnEnable()
{
} }
// Update is called once per frame
void Update()
/// <summary>
/// OnDisable is called when the behaviour becomes disabled.
/// </summary>
private void OnDisable()
{
}
/// <summary>
/// Update is called once per frame
/// </summary>
private void FixedUpdate()
{
undoDoneThisFrame = false;
UpdateTransform();
}
#endregion MonoBehaviour Functions
#region Class Functionality
private void UpdateTransform()
{
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);
m_oarRigidbody.MovePosition(m_rightHand.transform.position - direction * m_distanceFromRightHand);
m_oarRigidbody.MoveRotation(rotation);
}
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}");
}
} }
}
#endregion Class Functionality
#region Editor Functions
/// <summary>
/// Called when the Component is created or Reset from the Inspector
/// </summary>
private void Reset()
{
m_oarRigidbody = GetComponentInChildren<Rigidbody>();
}
#endregion Editor Functions
}

+ 86
- 0
Assets/Scripts/Player/RowController.cs View File

@ -0,0 +1,86 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
using NaughtyAttributes;
/// <summary>
///
/// </summary>
public class RowController : MonoBehaviour
{
#region Inspector Fields
[SerializeField]
private Transform m_topHand;
[SerializeField]
private Transform m_bottomHand;
[SerializeField, BoxGroup("Settings"), Range(0.0f, 1.0f)]
private float m_armRange = 1;
[SerializeField, BoxGroup("Settings"), Range(0.0f, 1.0f)]
private float m_armSpeed = 0.2f;
[SerializeField, BoxGroup("Input")]
private InputActionProperty m_inputAxis;
#endregion Inspector Fields
#region Private Fields
#endregion Private Fields
#region Getters
#endregion Getters
#region MonoBehaviour Functions
/// <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 Update()
{
}
#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/Scripts/Player/RowController.cs.meta View File

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

+ 1030
- 0
Assets/Settings/PlayerInput.inputactions
File diff suppressed because it is too large
View File


+ 14
- 0
Assets/Settings/PlayerInput.inputactions.meta View File

@ -0,0 +1,14 @@
fileFormatVersion: 2
guid: 5007e9a2e21d73f43b8fbe101756449d
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 11500000, guid: 8404be70184654265930450def6a9037, type: 3}
generateWrapperCode: 0
wrapperCodePath:
wrapperClassName:
wrapperCodeNamespace: UnityEngine.InputSystem

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

size 1323

Loading…
Cancel
Save