Skip to content
Snippets Groups Projects
Commit 4d9c88b8 authored by Sam Mattiussi's avatar Sam Mattiussi
Browse files

Switch student trigger by distance detection

parent 59821e2b
No related branches found
No related tags found
No related merge requests found
......@@ -107,6 +107,9 @@ namespace TeachR.ApplicationManager
/// pin used by coaches to gain access to the virtual classroom via central server
/// </summary>
public static string ClassroomPin { get; set; } = "0000";
public static bool IsAutomatedBehaviour { get; set; } = false;
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
......
using System.Collections;
using UnityEngine;
using TeachR.ApplicationManager;
using TeachR.RTC;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
......@@ -11,6 +10,7 @@ namespace TeachR.Student
{
public class BehaviourController : MonoBehaviour
{
private const float TriggerDistance = 2f;
private const float CrossFadeTime = 0.4f;
public string LastGoodBehaviour = "Idle";
......@@ -34,8 +34,20 @@ namespace TeachR.Student
public bool IsDistorting { get; private set; }
public bool TeacherInPersonalSpace { get; private set; }
private FindPartner fp;
private float distortionStartTimePoint;
#region Animator Properties
private static readonly int IsLeftHanded = Animator.StringToHash("isLeftHanded");
private static readonly int IsTall = Animator.StringToHash("isTall");
private static readonly int CycleOffset = Animator.StringToHash("CycleOffset");
private static readonly int SitsRight = Animator.StringToHash("sitsRight");
private static readonly int Horizontal = Animator.StringToHash("Horizontal");
private static readonly int IsReceiver = Animator.StringToHash("isReceiver");
private static readonly int RandomImpulse = Animator.StringToHash("randomImpulse");
#endregion
public void Init(StudentController sc)
{
......@@ -51,12 +63,11 @@ namespace TeachR.Student
bool sitsRight = transform.name.Contains("R");
animator = sc.Model.GetComponent<Animator>();
animator.SetBool("isTall", sc.StudentObj.IsTall);
animator.SetBool("isLeftHanded", sc.StudentObj.IsLeftHanded);
animator.SetBool(IsTall, sc.StudentObj.IsTall);
animator.SetBool(IsLeftHanded, sc.StudentObj.IsLeftHanded);
nameSeededRandomValue = Mathf.Abs((float)sc.StudentObj.Name.GetHashCode() / (float)int.MaxValue);
animator.SetFloat("CycleOffset", nameSeededRandomValue);
animator.SetBool("sitsRight", sitsRight);
// AnimatorParameter "Labpartner" is set in class "UseBunsenBurner"
animator.SetFloat(CycleOffset, nameSeededRandomValue);
animator.SetBool(SitsRight, sitsRight);
Ik = sc.Model.GetComponent<IKStudentControl>();
......@@ -64,14 +75,27 @@ namespace TeachR.Student
StartCoroutine(NonScriptedClassBehaviour());
}
void OnTriggerEnter(Collider other)
private void FixedUpdate()
{
if (MenuDataHolder.IsAutomaticIntervention &&
//other.gameObject.transform == AllStudentAttributes.Teacher &&
other.tag == "Player" &&
CurrentBehaviour != LastGoodBehaviour && IsDistorting)
var teacher = AllStudentAttributes.Teacher.position;
var teacherPos = new Vector2(teacher.x, teacher.z);
var position = transform.position;
var studentPos = new Vector2(position.x, position.z);
if (Vector2.Distance(teacherPos, studentPos) < TriggerDistance)
{
TriggerLastGoodBehaviour();
TeacherInPersonalSpace = true;
if (MenuDataHolder.IsAutomaticIntervention &&
CurrentBehaviour != LastGoodBehaviour && IsDistorting && !MenuDataHolder.IsAutomatedBehaviour)
{
TriggerLastGoodBehaviour();
}
}
else
{
TeacherInPersonalSpace = false;
}
}
......@@ -91,7 +115,8 @@ namespace TeachR.Student
{
// Calculates a projection of a partners position onto the students local XZ-plane (i.e. (Left, Front) corresponds to partners position on unit circle)
// This could be used later to blend cleanly between conversation angles, but should also be a fairly efficient check (i.e. Left > 0, Front > 0) in the animator
animator.SetFloat("Horizontal", Vector3.Dot(transform.right, (fp.Partner.position - transform.position).normalized));
animator.SetFloat(Horizontal,
Vector3.Dot(transform.right, (fp.Partner.position - transform.position).normalized));
// sc.StudentAnimator.SetFloat("Front", Vector3.Dot(transform.forward, (ConversationPartner.position - transform.position).normalized));
}
......@@ -100,7 +125,8 @@ namespace TeachR.Student
MenuDataHolder.MisbehaviourSolved++;
MenuDataHolder.TotalInterventionTime += Time.time - distortionStartTimePoint;
IsDistorting = false;
TimeDelayToLastMisbehaviour = 0f; // DateTime.Now.Minute * 60 + DateTime.Now.Second; // TODO Where/How is this actually used?
TimeDelayToLastMisbehaviour =
0f; // DateTime.Now.Minute * 60 + DateTime.Now.Second; // TODO Where/How is this actually used?
Disrupt(LastGoodBehaviour);
}
......@@ -175,7 +201,7 @@ namespace TeachR.Student
FacePartner();
// Set bool to trigger animations for actors/receivers accordingly
animator.SetBool("isReceiver", !origin);
animator.SetBool(IsReceiver, !origin);
if (origin)
{
......@@ -212,7 +238,7 @@ namespace TeachR.Student
{
//look for animations to illustrate talking students and get a random animationclip
float randomImpulse = Random.value;
animator.SetFloat("randomImpulse", randomImpulse);
animator.SetFloat(RandomImpulse, randomImpulse);
Ik.Follow = !IsDistorting && LastGoodBehaviour == "Impulse";
Disrupt("Impulse");
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment