diff --git a/Assets/Prefabs/Child.prefab b/Assets/Prefabs/Child.prefab index 9c7e225..ca14407 100644 --- a/Assets/Prefabs/Child.prefab +++ b/Assets/Prefabs/Child.prefab @@ -1070,7 +1070,6 @@ MonoBehaviour: pillow: {fileID: 0} Mom: {fileID: 0} Animator: {fileID: 9580008} - target: {fileID: 0} --- !u!114 &11446734 MonoBehaviour: m_ObjectHideFlags: 1 @@ -1094,7 +1093,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 567fe96dcacb08f4ab716a98ce99fc88, type: 3} m_Name: m_EditorClassIdentifier: - minAngleRange: 10 + minAngleRange: 30 --- !u!135 &13545904 SphereCollider: m_ObjectHideFlags: 1 @@ -1248,7 +1247,7 @@ Prefab: objectReference: {fileID: 0} - target: {fileID: 0} propertyPath: minAngleRange - value: 10 + value: 30 objectReference: {fileID: 0} m_RemovedComponents: [] m_ParentPrefab: {fileID: 0} diff --git a/Assets/Scripts/AutoTarget.cs b/Assets/Scripts/AutoTarget.cs index 178e3ad..bfebfc6 100644 --- a/Assets/Scripts/AutoTarget.cs +++ b/Assets/Scripts/AutoTarget.cs @@ -5,7 +5,7 @@ using System.Collections.Generic; public class AutoTarget : MonoBehaviour { private List targets; - public float minAngleRange = 20f; + public float minAngleRange = 30f; // Use this for initialization void Start () diff --git a/Assets/Scripts/Child.cs b/Assets/Scripts/Child.cs index 42d3ed5..01d454f 100644 --- a/Assets/Scripts/Child.cs +++ b/Assets/Scripts/Child.cs @@ -23,7 +23,6 @@ public class Child : MonoBehaviour private bool _isSleeping; private float _invulnerableTime; private Bed _currentBed; - public Transform target; private int _index; private bool _isPushed = false; @@ -32,6 +31,8 @@ public class Child : MonoBehaviour private float _stunTime; + private AutoTarget _autoTarget; + public int Index { get { return _index; } @@ -47,6 +48,7 @@ public class Child : MonoBehaviour void Awake() { _rb = GetComponent(); + _autoTarget = GetComponent(); } void Update() @@ -54,11 +56,7 @@ public class Child : MonoBehaviour Animator.SetBool("IsOnBed", GetBed()); _isGrounded = IsGrounded(); - Debug.Log(_isGrounded); - // look at the target - if (target != null) { - transform.LookAt(target); - } + // We move the child depending on the camera orientation @@ -185,12 +183,14 @@ public class Child : MonoBehaviour return colliders.Length > 0 ? colliders[0].GetComponent() : null; } - internal void Throw() { + public void Throw() { if (pillow != null) { Vector3 direction; + Transform target = _autoTarget.GetTarget(transform.forward); + if (target != null) { direction = target.transform.position - pillow.transform.position; } @@ -205,6 +205,8 @@ public class Child : MonoBehaviour pillow.IsOwned = false; pillow = null; + + target = null; } } diff --git a/Assets/Scripts/ChildController.cs b/Assets/Scripts/ChildController.cs index 2f33e1d..a63059e 100644 --- a/Assets/Scripts/ChildController.cs +++ b/Assets/Scripts/ChildController.cs @@ -75,23 +75,15 @@ public class ChildController : MonoBehaviour } if (xLookingValue != 0 || zLookingValue != 0) { - //Transform target = _autoTarget.GetTarget(new Vector3(xLookingValue, 0, zLookingValue)); - Transform target = _autoTarget.GetTarget(xLookingValue, zLookingValue); - _child.target = target; - if (_child.target != null) { - transform.LookAt(_child.target); - } - else { - transform.eulerAngles = new Vector3( + transform.eulerAngles = new Vector3( transform.eulerAngles.x, Mathf.Atan2(xLookingValue, zLookingValue) * Mathf.Rad2Deg -90, // -90 to correct forward facing angle... transform.eulerAngles.z); - } + } else { - _child.target = null; // no auto targeting when not actively pressing the joystick in a direction - + // if player is not look with the right joystick, then face the direction we're going // if left joystick is used, else we don't change the facing direction if (xValue != 0 || zValue!= 0) {