stabilized character interactions
This commit is contained in:
parent
6a72fda395
commit
ed145ddc56
32 changed files with 264 additions and 53 deletions
|
@ -13,19 +13,19 @@ AnimatorController:
|
|||
m_DefaultFloat: 0
|
||||
m_DefaultInt: 0
|
||||
m_DefaultBool: 0
|
||||
m_Controller: {fileID: 0}
|
||||
m_Controller: {fileID: 9100000}
|
||||
- m_Name: Interrupted
|
||||
m_Type: 9
|
||||
m_DefaultFloat: 0
|
||||
m_DefaultInt: 0
|
||||
m_DefaultBool: 0
|
||||
m_Controller: {fileID: 0}
|
||||
m_Controller: {fileID: 9100000}
|
||||
- m_Name: PassingMessage
|
||||
m_Type: 9
|
||||
m_DefaultFloat: 0
|
||||
m_DefaultInt: 0
|
||||
m_DefaultBool: 0
|
||||
m_Controller: {fileID: 0}
|
||||
m_Controller: {fileID: 9100000}
|
||||
m_AnimatorLayers:
|
||||
- serializedVersion: 5
|
||||
m_Name: Base Layer
|
||||
|
@ -170,6 +170,30 @@ AnimatorStateTransition:
|
|||
m_InterruptionSource: 0
|
||||
m_OrderedInterruption: 1
|
||||
m_CanTransitionToSelf: 1
|
||||
--- !u!1101 &1101234958992700582
|
||||
AnimatorStateTransition:
|
||||
m_ObjectHideFlags: 1
|
||||
m_PrefabParentObject: {fileID: 0}
|
||||
m_PrefabInternal: {fileID: 0}
|
||||
m_Name:
|
||||
m_Conditions:
|
||||
- m_ConditionMode: 1
|
||||
m_ConditionEvent: Interrupted
|
||||
m_EventTreshold: 0
|
||||
m_DstStateMachine: {fileID: 0}
|
||||
m_DstState: {fileID: 1102150790202348572}
|
||||
m_Solo: 0
|
||||
m_Mute: 0
|
||||
m_IsExit: 0
|
||||
serializedVersion: 3
|
||||
m_TransitionDuration: 0
|
||||
m_TransitionOffset: 0.00047320855
|
||||
m_ExitTime: 1.0000001
|
||||
m_HasExitTime: 0
|
||||
m_HasFixedDuration: 1
|
||||
m_InterruptionSource: 0
|
||||
m_OrderedInterruption: 1
|
||||
m_CanTransitionToSelf: 1
|
||||
--- !u!1101 &1101240174848402812
|
||||
AnimatorStateTransition:
|
||||
m_ObjectHideFlags: 3
|
||||
|
@ -279,6 +303,7 @@ AnimatorState:
|
|||
m_Transitions:
|
||||
- {fileID: 1101240174848402812}
|
||||
- {fileID: 1101154328280627494}
|
||||
- {fileID: 1101234958992700582}
|
||||
m_StateMachineBehaviours: []
|
||||
m_Position: {x: 50, y: 50, z: 0}
|
||||
m_IKOnFeet: 0
|
||||
|
|
|
@ -23,7 +23,7 @@ MonoBehaviour:
|
|||
VoiceServerPort: 5055
|
||||
JoinLobby: 0
|
||||
EnableLobbyStatistics: 0
|
||||
PunLogging: 1
|
||||
PunLogging: 0
|
||||
NetworkLogging: 1
|
||||
RunInBackground: 1
|
||||
RpcList:
|
||||
|
|
|
@ -2152,7 +2152,8 @@ MonoBehaviour:
|
|||
_queuedInteractorId: -1
|
||||
_isInteracting: 0
|
||||
interactions: []
|
||||
spyInteractions: []
|
||||
spyInteractions:
|
||||
- {fileID: 11400000, guid: 218e2ddac8223e349a855bdae23819ab, type: 2}
|
||||
currentState: {fileID: 11400000, guid: 1c694dfd46dd4e44b94f7853724fa1c0, type: 2}
|
||||
remainState: {fileID: 11400000, guid: 5eb84557ff3e09f42b843e0b09653774, type: 2}
|
||||
navMeshAgent: {fileID: 0}
|
||||
|
|
|
@ -12,10 +12,16 @@ public class IdleClickAction : Action
|
|||
{
|
||||
ProgressPanelController.ActivePanel.Hide();
|
||||
controller.SelectedInteraction = null;
|
||||
controller.Interactor = null;
|
||||
controller.SelectedObject = null;
|
||||
}
|
||||
|
||||
public override void Act(StateController controller)
|
||||
{
|
||||
// Decline interactions here
|
||||
if (Input.GetKeyDown(KeyCode.D))
|
||||
controller.Interactor = null;
|
||||
|
||||
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
{
|
||||
|
@ -25,7 +31,6 @@ public class IdleClickAction : Action
|
|||
{
|
||||
// Debug.Log("Selected object set to " + selectableObject.name);
|
||||
controller.SelectedObject = selectableObject;
|
||||
controller.Destination = selectableObject.gameObject.transform.position;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -34,6 +39,8 @@ public class IdleClickAction : Action
|
|||
controller.SelectedObject = null;
|
||||
RaycastToMoveController(controller, ray);
|
||||
}
|
||||
if (controller.SelectedObject && !controller.IsInteracting)
|
||||
controller.Destination = controller.SelectedObject.transform.position;
|
||||
}
|
||||
|
||||
// Check if StateController clicked on a Selectable Object
|
||||
|
@ -45,7 +52,7 @@ public class IdleClickAction : Action
|
|||
if (Physics.Raycast(ray, out hit, 100.0f, mask))
|
||||
{
|
||||
SelectableObject selectable = hit.collider.gameObject.GetComponentInParent<SelectableObject>();
|
||||
if (selectable != null && (StateController)selectable != controller && selectable.HasInteractions())
|
||||
if (selectable != null && selectable != controller && selectable.HasInteractions())
|
||||
{
|
||||
selectableObject = selectable;
|
||||
return true;
|
||||
|
|
|
@ -10,7 +10,7 @@ public class PromptInteractionsAction : Action {
|
|||
string objectInteractionText = "Press 'E' to interact with ";
|
||||
if (ReceivedInteraction(controller))
|
||||
{
|
||||
InteractionPanelController.Reveal(controller.Interactor.name);
|
||||
InteractionPanelController.Reveal(controller.Interactor.name/* + " is trying to " + controller.Interactor.SelectedInteraction.interactionDescription*/);
|
||||
}
|
||||
else if (SelectedObjectAvailable(controller))
|
||||
{
|
||||
|
|
|
@ -6,12 +6,16 @@ public class SpyInteractAction : Action
|
|||
{
|
||||
public override void StartAct(StateController controller)
|
||||
{
|
||||
controller.FaceSelectedObject();
|
||||
controller.characterAnimator.SetTrigger(controller.SelectedInteraction.characterInteraction);
|
||||
Vector3 awayDirection =(controller.transform.position - controller.SelectedObject.transform.position).normalized;
|
||||
Vector3 newPos = controller.SelectedObject.transform.position + awayDirection * controller.SelectedInteraction.interactionDistance;
|
||||
controller.navMeshAgent.stoppingDistance = 0.0f;
|
||||
controller.Destination = newPos;
|
||||
}
|
||||
|
||||
public override void Act(StateController controller)
|
||||
{
|
||||
controller.FaceSelectedObject();
|
||||
AnimatorStateInfo info = controller.animator.GetCurrentAnimatorStateInfo(0);
|
||||
if (info.IsName(CharacterAnimator.GetParamName(controller.SelectedInteraction.characterInteraction)))
|
||||
{
|
||||
|
|
|
@ -6,7 +6,7 @@ public class WaitForInteractionAcceptance : Action
|
|||
public override void StartAct(StateController controller)
|
||||
{
|
||||
// Todo: Remove this line once the "interaction selector" UI is finished
|
||||
controller.SelectedInteraction = controller.SelectedObject.interactions[0];
|
||||
controller.SelectedInteraction = GetFirstInteraction(controller);
|
||||
controller.InitiateInteractionWithSelectedObject();
|
||||
ProgressPanelController.ActivePanel.Reveal(controller.SelectedInteraction.interactionDescription);
|
||||
}
|
||||
|
@ -15,5 +15,12 @@ public class WaitForInteractionAcceptance : Action
|
|||
{
|
||||
//Debug.Log("Finished waiting for acceptance");
|
||||
}
|
||||
|
||||
private Interaction GetFirstInteraction(StateController controller)
|
||||
{
|
||||
if (controller.SelectedObject.interactions.Length > 0)
|
||||
return controller.SelectedObject.interactions[0];
|
||||
return controller.SelectedObject.spyInteractions[0];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,13 +8,22 @@ public class WaitInPlaceAction : Action {
|
|||
public override void StartAct(StateController controller)
|
||||
{
|
||||
// Debug.Log("Waiting in place!");
|
||||
controller.FaceInteractor();
|
||||
if (!controller.IsInteracting)
|
||||
controller.IsInteracting = true;
|
||||
controller.Destination = controller.transform.position;
|
||||
}
|
||||
|
||||
public override void Act(StateController controller)
|
||||
{
|
||||
controller.FaceInteractor();
|
||||
}
|
||||
|
||||
public override void EndAct(StateController controller)
|
||||
{
|
||||
// Debug.Log("Done waiting in place!");
|
||||
if (controller.characterAnimator.GetTrigger(CharacterAnimator.Params.Interrupted))
|
||||
controller.Interactor.characterAnimator.SetTrigger(CharacterAnimator.Params.Interrupted);
|
||||
controller.Interactor = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,8 +9,6 @@ public class InitiatedInteractionDecision : Decision
|
|||
{
|
||||
return Input.GetKeyDown(KeyCode.E) &&
|
||||
InteractionPanelController.InteractionPrompted() &&
|
||||
controller.SelectedObject != null;/* &&
|
||||
!controller.SelectedObject.IsInteracting &&
|
||||
controller.SelectedObject.Interactor == null;*/
|
||||
controller.SelectedObject != null;
|
||||
}
|
||||
}
|
|
@ -2,8 +2,8 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
[CreateAssetMenu(menuName = "CharacterStateMachine/Decisions/InteractionAccepted")]
|
||||
public class InteractionAcceptedDecision : Decision
|
||||
[CreateAssetMenu(menuName = "CharacterStateMachine/Decisions/ObjectAcceptedInteraction")]
|
||||
public class ObjectAcceptedInteractionDecision : Decision
|
||||
{
|
||||
public override bool Decide(StateController controller)
|
||||
{
|
|
@ -0,0 +1,15 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
[CreateAssetMenu(menuName = "CharacterStateMachine/Decisions/ObjectDeclinedInteraction")]
|
||||
class ObjectDeclinedInteractionDecision : Decision
|
||||
{
|
||||
public override bool Decide(StateController controller)
|
||||
{
|
||||
return controller.IsInteractionRejected();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: bf964d8e3b4f70d4187bbc4b0e7061db
|
||||
timeCreated: 1507493070
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -2,7 +2,7 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
[CreateAssetMenu(menuName = "CharacterStateMachine/Decisions/WaitForAnimation")]
|
||||
[CreateAssetMenu(menuName = "CharacterStateMachine/Decisions/WaitForTransition")]
|
||||
public class WaitForTransitionDecision : Decision
|
||||
{
|
||||
public string fromState, toState;
|
||||
|
@ -13,6 +13,7 @@ public class WaitForTransitionDecision : Decision
|
|||
var currentTransition = controller.animator.GetAnimatorTransitionInfo(0);
|
||||
if (currentTransition.IsName(transitionName))
|
||||
{
|
||||
controller.SelectedInteraction.ExecuteResult(controller);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
[CreateAssetMenu(menuName = "CharacterStateMachine/Decisions/YouAcceptedInteraction")]
|
||||
class YouAcceptedInteractionDecision : Decision
|
||||
{
|
||||
public override bool Decide(StateController controller)
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.E))
|
||||
return controller.Interactor != null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: fe5a2c8c5f93bef4aafc593da5decd3b
|
||||
timeCreated: 1507361522
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -7,9 +7,33 @@ public class Interaction : ScriptableObject
|
|||
public string interactionDescription;
|
||||
public CharacterAnimator.Params characterInteraction;
|
||||
public InteractionResult result;
|
||||
public float initialRotation;
|
||||
public float objectInitialRotation;
|
||||
public float interactionDistance = 1.0f;
|
||||
|
||||
public enum InteractionResult
|
||||
{
|
||||
Nothing, SpyMissionComplete
|
||||
}
|
||||
|
||||
public void ExecuteResult(StateController controller)
|
||||
{
|
||||
switch(result)
|
||||
{
|
||||
case InteractionResult.Nothing:
|
||||
break;
|
||||
case InteractionResult.SpyMissionComplete:
|
||||
SpyMissionComplete(controller);
|
||||
break;
|
||||
default:
|
||||
Debug.LogError("Invalid result selected for execution");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------- Result functions ---------------------------------
|
||||
void SpyMissionComplete(StateController controller)
|
||||
{
|
||||
Debug.Log("Completed mission");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
using System.Collections;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public abstract class SelectableObject : Photon.PunBehaviour
|
||||
public abstract class SelectableObject : Photon.PunBehaviour, IEquatable<SelectableObject>
|
||||
{
|
||||
// PhotonView Id of interacting character
|
||||
[SerializeField]
|
||||
|
@ -99,4 +100,9 @@ public abstract class SelectableObject : Photon.PunBehaviour
|
|||
{
|
||||
_queuedInteractorId = viewId;
|
||||
}
|
||||
|
||||
public virtual bool Equals(SelectableObject other)
|
||||
{
|
||||
return photonView.viewID == other.photonView.viewID;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,5 +9,5 @@ MonoBehaviour:
|
|||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 3f9fa98245568d74ca9c5ea641087346, type: 3}
|
||||
m_Name: InteractionAccepted
|
||||
m_Name: ObjectAcceptedInteraction
|
||||
m_EditorClassIdentifier:
|
|
@ -8,8 +8,6 @@ MonoBehaviour:
|
|||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 5a6a367e35acd7e44a0a598eaa1d6700, type: 3}
|
||||
m_Name: RemainState
|
||||
m_Script: {fileID: 11500000, guid: bf964d8e3b4f70d4187bbc4b0e7061db, type: 3}
|
||||
m_Name: ObjectDeclinedInteraction
|
||||
m_EditorClassIdentifier:
|
||||
actions: []
|
||||
transitions: []
|
|
@ -1,6 +1,6 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5eb84557ff3e09f42b843e0b09653774
|
||||
timeCreated: 1506923361
|
||||
guid: a3e30efde30a6294ba3fee0fa08b7417
|
||||
timeCreated: 1507493116
|
||||
licenseType: Free
|
||||
NativeFormatImporter:
|
||||
mainObjectFileID: 11400000
|
|
@ -8,6 +8,6 @@ MonoBehaviour:
|
|||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 56a0f4e2f06493a4e97f596ad8d0ead1, type: 3}
|
||||
m_Name: InteractionCompleted
|
||||
m_Script: {fileID: 11500000, guid: fe5a2c8c5f93bef4aafc593da5decd3b, type: 3}
|
||||
m_Name: YouAcceptedInteraction
|
||||
m_EditorClassIdentifier:
|
|
@ -1,6 +1,6 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b7c91a8a56fb7a54abe6a9098297f8bb
|
||||
timeCreated: 1507182216
|
||||
guid: 4e6653d3fb6849f408ed8adb9005a439
|
||||
timeCreated: 1507362010
|
||||
licenseType: Free
|
||||
NativeFormatImporter:
|
||||
mainObjectFileID: 11400000
|
|
@ -13,4 +13,6 @@ MonoBehaviour:
|
|||
m_EditorClassIdentifier:
|
||||
interactionDescription: Telling Secret...
|
||||
characterInteraction: 1
|
||||
result: 0
|
||||
result: 1
|
||||
initialRotation: -60
|
||||
objectInitialRotation: -60
|
|
@ -17,4 +17,7 @@ MonoBehaviour:
|
|||
transitions:
|
||||
- decision: {fileID: 11400000, guid: ce72eaa68e3e07147a3aa891ff8f4a13, type: 2}
|
||||
trueState: {fileID: 11400000, guid: ed2af5dc9d7af8b4580705c19d61fb57, type: 2}
|
||||
falseState: {fileID: 11400000, guid: 5eb84557ff3e09f42b843e0b09653774, type: 2}
|
||||
transitionValue: 1
|
||||
- decision: {fileID: 11400000, guid: 4e6653d3fb6849f408ed8adb9005a439, type: 2}
|
||||
trueState: {fileID: 11400000, guid: 32814da7acb45a64792eaf699c6043da, type: 2}
|
||||
transitionValue: 1
|
||||
|
|
|
@ -21,3 +21,6 @@ MonoBehaviour:
|
|||
- decision: {fileID: 11400000, guid: d1e5ed22b1756104794e4cdad03e7bd0, type: 2}
|
||||
trueState: {fileID: 11400000, guid: f92df2056f917ce45921c2f8b94c75dd, type: 2}
|
||||
transitionValue: 1
|
||||
- decision: {fileID: 11400000, guid: a3e30efde30a6294ba3fee0fa08b7417, type: 2}
|
||||
trueState: {fileID: 11400000, guid: 1c694dfd46dd4e44b94f7853724fa1c0, type: 2}
|
||||
transitionValue: 1
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_PrefabParentObject: {fileID: 0}
|
||||
m_PrefabInternal: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 5a6a367e35acd7e44a0a598eaa1d6700, type: 3}
|
||||
m_Name: WaitingForOtherToCompleteInteraction
|
||||
m_EditorClassIdentifier:
|
||||
actions:
|
||||
- {fileID: 11400000, guid: b241bf77cda4ed84992fa09741f347ef, type: 2}
|
||||
- {fileID: 11400000, guid: a239cb93f4d18fa4baf7a01d44718dbb, type: 2}
|
||||
transitions:
|
||||
- decision: {fileID: 11400000, guid: aca961c852aa698469b7c4d36142c175, type: 2}
|
||||
trueState: {fileID: 11400000, guid: 1c694dfd46dd4e44b94f7853724fa1c0, type: 2}
|
||||
transitionValue: 0
|
||||
- decision: {fileID: 11400000, guid: 54c4574724be54540892c8db5aff93d1, type: 2}
|
||||
trueState: {fileID: 11400000, guid: 1c694dfd46dd4e44b94f7853724fa1c0, type: 2}
|
||||
transitionValue: 1
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 32814da7acb45a64792eaf699c6043da
|
||||
timeCreated: 1507361581
|
||||
licenseType: Free
|
||||
NativeFormatImporter:
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -19,6 +19,8 @@ public class StateController : SelectableObject
|
|||
private SelectableObject _selectedObject;
|
||||
private Interaction _selectedInteraction;
|
||||
private Coroutine _roamCoroutine;
|
||||
private static float _startInteractionProgressLimit = 0.3f;
|
||||
private static float _endInteractionProgressLimit = 0.8f;
|
||||
|
||||
|
||||
void Awake()
|
||||
|
@ -44,8 +46,6 @@ public class StateController : SelectableObject
|
|||
if (photonView.isMine)
|
||||
{
|
||||
currentState.UpdateState(this);
|
||||
if (SelectedObject)
|
||||
Destination = SelectedObject.transform.position;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -143,12 +143,22 @@ public class StateController : SelectableObject
|
|||
{
|
||||
return IsInteracting && SelectedObject.IsInteracting && SelectedObject.Interactor == this;
|
||||
}
|
||||
public bool IsInteractionRejected()
|
||||
{
|
||||
return SelectedObject.Interactor != this;
|
||||
}
|
||||
|
||||
|
||||
public void FinishInteraction()
|
||||
{
|
||||
IsInteracting = false;
|
||||
SelectedObject.Interactor = null;
|
||||
SelectedObject = null;
|
||||
if (IsInteracting)
|
||||
IsInteracting = false;
|
||||
if (SelectedObject)
|
||||
{
|
||||
if (SelectedObject.IsInteracting)
|
||||
SelectedObject.IsInteracting = false;
|
||||
SelectedObject = null;
|
||||
}
|
||||
}
|
||||
|
||||
public Interaction SelectedInteraction
|
||||
|
@ -163,22 +173,6 @@ public class StateController : SelectableObject
|
|||
}
|
||||
}
|
||||
|
||||
public void FaceInteractor()
|
||||
{
|
||||
if (Interactor == null)
|
||||
Debug.LogError("Cannot face a null Interactor");
|
||||
|
||||
transform.LookAt(Interactor.transform);
|
||||
}
|
||||
|
||||
public void FaceSelectedObject()
|
||||
{
|
||||
if (SelectedObject == null)
|
||||
Debug.LogError("Cannot face a null SelectedObject");
|
||||
|
||||
transform.LookAt(SelectedObject.transform);
|
||||
}
|
||||
|
||||
public void StartRoaming()
|
||||
{
|
||||
_roamCoroutine = StartCoroutine(Roam());
|
||||
|
@ -197,4 +191,45 @@ public class StateController : SelectableObject
|
|||
Destination = GetRandomLocation();
|
||||
}
|
||||
}
|
||||
|
||||
public void FaceSelectedObject()
|
||||
{
|
||||
float progress = animator.GetCurrentAnimatorStateInfo(0).normalizedTime;
|
||||
Vector3 otherPos = SelectedObject.transform.position;
|
||||
float initialRotation = SelectedInteraction.initialRotation;
|
||||
SetFacingRotation(otherPos, progress, initialRotation);
|
||||
}
|
||||
|
||||
public void FaceInteractor()
|
||||
{
|
||||
if (Interactor == null)
|
||||
Debug.LogError("Cannot face a null Interactor");
|
||||
|
||||
float progress = Interactor.animator.GetCurrentAnimatorStateInfo(0).normalizedTime;
|
||||
Vector3 otherPos = Interactor.transform.position;
|
||||
if (Interactor.SelectedInteraction == null)
|
||||
return;
|
||||
float initialRotation = Interactor.SelectedInteraction.objectInitialRotation;
|
||||
SetFacingRotation(otherPos, progress, initialRotation);
|
||||
}
|
||||
|
||||
private void SetFacingRotation(Vector3 otherPos, float progress, float initialRotation)
|
||||
{
|
||||
if (progress > _startInteractionProgressLimit && progress < _endInteractionProgressLimit)
|
||||
return;
|
||||
|
||||
Vector3 pos = transform.position;
|
||||
Vector3 facingDirection = (otherPos - pos).normalized;
|
||||
Quaternion facingRotation = Quaternion.FromToRotation(Vector3.forward, facingDirection);
|
||||
|
||||
if (progress < _startInteractionProgressLimit)
|
||||
{
|
||||
Quaternion adjustedRotation = facingRotation * Quaternion.Euler(0, initialRotation, 0);
|
||||
transform.rotation = Quaternion.Slerp(transform.rotation, adjustedRotation, Time.deltaTime * 5.0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
transform.rotation = Quaternion.Slerp(transform.rotation, facingRotation, Time.deltaTime * 5.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue