mirror of
https://github.com/ConjureETS/PillowFight.git
synced 2026-03-25 17:40:59 +00:00
Merge branch 'master' of https://github.com/ConjureETS/PillowFight
This commit is contained in:
commit
275bec897d
Binary file not shown.
@ -25,22 +25,28 @@ public class AutoTarget : MonoBehaviour {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Transform GetTarget(Vector3 lookingAngle) {
|
public Transform GetTarget(Vector3 lookingAngle) {
|
||||||
|
|
||||||
Transform closest = null;
|
Transform closest = null;
|
||||||
float minAngle = minAngleRange;
|
float minAngle = minAngleRange;
|
||||||
|
|
||||||
|
Debug.Log("looking direction:" + lookingAngle);
|
||||||
|
|
||||||
|
|
||||||
foreach (Transform t in targets) {
|
foreach (Transform t in targets) {
|
||||||
Vector3 targetDirection = t.transform.position - transform.position;
|
Vector3 targetDirection = t.transform.position - transform.position;
|
||||||
|
|
||||||
|
float realAngle = Mathf.Atan2(targetDirection.z, targetDirection.x) * Mathf.Rad2Deg;
|
||||||
|
Debug.Log("real angle:" + realAngle);
|
||||||
|
|
||||||
|
float lookAngle = Mathf.Atan2(lookingAngle.z, lookingAngle.x) * Mathf.Rad2Deg;
|
||||||
|
Debug.Log("look angle:" + lookAngle);
|
||||||
|
|
||||||
float dot = Vector3.Dot(targetDirection, lookingAngle);
|
|
||||||
float angle = Mathf.Acos(dot) * Mathf.Rad2Deg;
|
|
||||||
|
|
||||||
if (angle < minAngle) {
|
if (Mathf.Abs(lookAngle - realAngle) < minAngle) {
|
||||||
minAngle = angle;
|
minAngle = lookAngle;
|
||||||
closest = t;
|
closest = t;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return closest;
|
return closest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -75,9 +75,19 @@ public class ChildController : MonoBehaviour
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (xLookingValue != 0 || zLookingValue != 0) {
|
if (xLookingValue != 0 || zLookingValue != 0) {
|
||||||
//transform.rotation = new Quaternion(0, 1, 0, Mathf.Atan2(zLookingValue, xLookingValue));
|
Transform target = _autoTarget.GetTarget(new Vector3(xLookingValue, 0, zLookingValue));
|
||||||
transform.eulerAngles = new Vector3(transform.eulerAngles.x, Mathf.Atan2(xLookingValue, zLookingValue) * Mathf.Rad2Deg, transform.eulerAngles.z);
|
|
||||||
_child.target = _autoTarget.GetTarget(new Vector3(xLookingValue, 0, zLookingValue));
|
_child.target = target;
|
||||||
|
if (_child.target != null) {
|
||||||
|
transform.LookAt(_child.target);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
transform.eulerAngles = new Vector3(
|
||||||
|
transform.eulerAngles.x,
|
||||||
|
Mathf.Atan2(xLookingValue, zLookingValue) * Mathf.Rad2Deg,
|
||||||
|
transform.eulerAngles.z);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2,6 +2,8 @@
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
|
||||||
public class Pillow : MonoBehaviour {
|
public class Pillow : MonoBehaviour {
|
||||||
|
|
||||||
|
public bool IsThrown = false;
|
||||||
|
|
||||||
// Use this for initialization
|
// Use this for initialization
|
||||||
void Start () {
|
void Start () {
|
||||||
@ -10,7 +12,20 @@ public class Pillow : MonoBehaviour {
|
|||||||
|
|
||||||
// Update is called once per frame
|
// Update is called once per frame
|
||||||
void Update () {
|
void Update () {
|
||||||
|
if (transform.position.y < -10) {
|
||||||
|
Destroy(this.gameObject);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OnTriggerEnter(Collider other) {
|
||||||
|
if (IsThrown && other.tag == "Player") {
|
||||||
|
|
||||||
|
Debug.Log("A child got hit by a pillow!");
|
||||||
|
|
||||||
|
//other.GetComponent<Child>().takeHit();
|
||||||
|
|
||||||
|
Destroy(this.gameObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user