diff --git a/Unity/TouchSensor.cs b/Unity/TouchSensor.cs index c34d86d..5c72771 100644 --- a/Unity/TouchSensor.cs +++ b/Unity/TouchSensor.cs @@ -16,6 +16,8 @@ namespace RoboidControl.Unity { get => (RoboidControl.TouchSensor)base.core; } + SphereCollider collider = null; + /// /// Start the Unity represention /// @@ -24,6 +26,7 @@ namespace RoboidControl.Unity { participant = FindAnyObjectByType(); SetCoreThing(new RoboidControl.TouchSensor(participant.site)); } + collider = GetComponent(); } /// @@ -42,7 +45,7 @@ namespace RoboidControl.Unity { rb.isKinematic = true; SphereCollider collider = gameObj.AddComponent(); - collider.radius = 0.02f; + collider.radius = 0.01f; collider.isTrigger = true; if (gameObj.transform.parent != null && gameObj.transform.localPosition.magnitude > 0) { @@ -53,6 +56,16 @@ namespace RoboidControl.Unity { return component; } + protected override void Update() { + base.Update(); + if (collider.radius == 0.01f && + this.transform.parent != null && this.transform.localPosition.magnitude > 0 + ) { + collider.radius = Vector3.Distance(this.transform.position, this.transform.parent.position) / 2; + this.transform.position = (this.transform.position + this.transform.parent.position) / 2; + } + } + private void OnTriggerEnter(Collider other) { Debug.Log("Touch?"); if (other.isTrigger) { diff --git a/src/Things/TouchSensor.cs b/src/Things/TouchSensor.cs index 88cb88d..93c7536 100644 --- a/src/Things/TouchSensor.cs +++ b/src/Things/TouchSensor.cs @@ -37,9 +37,9 @@ namespace RoboidControl { get { return _touchedSomething; } set { if (_touchedSomething != value) { - touchUpdated = true; _touchedSomething = value; } + touchUpdated = true; } } private bool touchUpdated = false;