Browse Source

fixed collisions

main
Joshua Reason 1 year ago
parent
commit
4664719219
8 changed files with 208 additions and 12 deletions
  1. BIN
      Assets/Scenes/Development/CharacterControllerTest.unity
  2. +90
    -0
      Assets/Scripts/Player/BoatRowController.cs
  3. +11
    -0
      Assets/Scripts/Player/BoatRowController.cs.meta
  4. +3
    -5
      Assets/Scripts/Player/HandController.cs
  5. +6
    -4
      Assets/Scripts/Player/OarController.cs
  6. +84
    -0
      Assets/Scripts/Player/PlayerController.cs
  7. +11
    -0
      Assets/Scripts/Player/PlayerController.cs.meta
  8. BIN
      ProjectSettings/DynamicsManager.asset

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

size 21726

+ 90
- 0
Assets/Scripts/Player/BoatRowController.cs View File

@ -0,0 +1,90 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using NaughtyAttributes;
/// <summary>
///
/// </summary>
public class BoatRowController : MonoBehaviour
{
#region Inspector Fields
public Collider m_oar;
public Transform m_oarTip;
#endregion Inspector Fields
#region Private Fields
private Vector3 m_lastKnownOarPosition;
#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
private void OnTriggerEnter(Collider other)
{
if(other == m_oar)
{
m_lastKnownOarPosition = m_oarTip.position;
}
}
void OnTriggerStay(Collider other)
{
if(other == m_oar)
{
Vector3 direction = m_lastKnownOarPosition - m_oarTip.position;
direction = Vector3.Project(direction,transform.forward);
}
}
#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/BoatRowController.cs.meta View File

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

+ 3
- 5
Assets/Scripts/Player/HandController.cs View File

@ -49,7 +49,7 @@ public class HandController : MonoBehaviour
#region Private Fields #region Private Fields
//Last input of player //Last input of player
private Vector2 m_desiredInput;
public Vector2 m_desiredInput;
private Vector3 m_startPosition; private Vector3 m_startPosition;
private Vector3 m_lastPosition; private Vector3 m_lastPosition;
@ -97,7 +97,7 @@ public class HandController : MonoBehaviour
/// </summary> /// </summary>
private void FixedUpdate() private void FixedUpdate()
{ {
UpdateHand(m_desiredInput);
//UpdateHand(m_desiredInput);
} }
#endregion MonoBehaviour Functions #endregion MonoBehaviour Functions
@ -108,7 +108,7 @@ public class HandController : MonoBehaviour
/// Called every fixed update to move the arms /// Called every fixed update to move the arms
/// </summary> /// </summary>
/// <param name="input"></param> /// <param name="input"></param>
private void UpdateHand(Vector2 input, bool registerUndo = true)
public void UpdateHand(Vector2 input, bool registerUndo = true)
{ {
m_lastPosition = transform.localPosition; m_lastPosition = transform.localPosition;
@ -129,8 +129,6 @@ public class HandController : MonoBehaviour
} }
} }
if (m_oar.isColliding())
UndoLastMovement();
} }

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

@ -80,15 +80,15 @@ public class OarController : MonoBehaviour
/// </summary> /// </summary>
private void FixedUpdate() private void FixedUpdate()
{ {
undoDoneThisFrame = false;
UpdateTransform();
//undoDoneThisFrame = false;
//UpdateTransform();
} }
#endregion MonoBehaviour Functions #endregion MonoBehaviour Functions
#region Class Functionality #region Class Functionality
private void UpdateTransform()
public void UpdateTransform()
{ {
Vector3 direction =(m_rightHand.transform.position - m_leftHand.transform.position).normalized; Vector3 direction =(m_rightHand.transform.position - m_leftHand.transform.position).normalized;
@ -96,6 +96,8 @@ public class OarController : MonoBehaviour
Quaternion rotation = Quaternion.LookRotation(forward, direction); Quaternion rotation = Quaternion.LookRotation(forward, direction);
transform.rotation = rotation;
transform.position = m_rightHand.transform.position - direction * m_distanceFromRightHand;
//MoveOarToPosition(m_rightHand.transform.position - direction * m_distanceFromRightHand); //MoveOarToPosition(m_rightHand.transform.position - direction * m_distanceFromRightHand);
m_oarRigidbody.MoveRotation(rotation); m_oarRigidbody.MoveRotation(rotation);
m_oarRigidbody.MovePosition(m_rightHand.transform.position - direction * m_distanceFromRightHand); m_oarRigidbody.MovePosition(m_rightHand.transform.position - direction * m_distanceFromRightHand);
@ -126,7 +128,7 @@ public class OarController : MonoBehaviour
Collider[] col = Physics.OverlapBox(transform.position + m_boxCollider.center, m_boxCollider.size / 2, rotation); Collider[] col = Physics.OverlapBox(transform.position + m_boxCollider.center, m_boxCollider.size / 2, rotation);
if (col.Intersect(m_forbiddenColliders).Any()) if (col.Intersect(m_forbiddenColliders).Any())
{ {
Debug.Log($"Colliding with: {string.Join(", ", col.Intersect(m_forbiddenColliders))}");
return true; return true;
} }
return false; return false;

+ 84
- 0
Assets/Scripts/Player/PlayerController.cs View File

@ -0,0 +1,84 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using NaughtyAttributes;
/// <summary>
///
/// </summary>
public class PlayerController : MonoBehaviour
{
#region Inspector Fields
public OarController oar;
public HandController leftHand;
public HandController rightHand;
#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 FixedUpdate()
{
leftHand.UpdateHand(leftHand.m_desiredInput);
rightHand.UpdateHand(rightHand.m_desiredInput);
oar.UpdateTransform();
if (oar.isColliding())
{
leftHand.UndoLastMovement();
rightHand.UndoLastMovement();
}
}
#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/PlayerController.cs.meta View File

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

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

size 1323 size 1323

Loading…
Cancel
Save