1
0
Fork 0

Door detection finished

This commit is contained in:
Saibotk 2018-04-24 08:03:54 +02:00
parent 638f18b54f
commit 3165cb4109
2 changed files with 7 additions and 11 deletions

View file

@ -70,11 +70,11 @@ public class Door : MonoBehaviour {
} }
private void Update() { private void Update() {
Player player = GameController.instance.GetPlayer(); //Player player = GameController.instance.GetPlayer();
Debug.DrawLine(gameObject.transform.position, gameObject.transform.position + new Vector3(toOuter.x, toOuter.y, 0)); //Debug.DrawLine(gameObject.transform.position, gameObject.transform.position + new Vector3(toOuter.x, toOuter.y, 0));
//Debug.DrawLine(new Vector3(), ( Vector2 ) ( parent.GetCenter() )); //Debug.DrawLine(new Vector3(), ( Vector2 ) ( parent.GetCenter() ));
Debug.DrawLine(player.gameObject.transform.position, gameObject.transform.position); //Debug.DrawLine(player.gameObject.transform.position, gameObject.transform.position);
Debug.DrawLine((Vector2)parent.GetCenter(), ( gameObject.transform.position )); //Debug.DrawLine((Vector2)parent.GetCenter(), ( gameObject.transform.position ));
} }
/// <summary> /// <summary>
@ -85,10 +85,10 @@ public class Door : MonoBehaviour {
// TODO only works correct for entering a room! // TODO only works correct for entering a room!
if ( collision.tag == "Player") { if ( collision.tag == "Player") {
Player player = collision.gameObject.GetComponent<Player>(); Player player = collision.gameObject.GetComponent<Player>();
Vector3 colliderToPlayer = player.gameObject.transform.position - gameObject.transform.position; Vector3 colliderToPlayer = player.gameObject.transform.position - ( gameObject.transform.position - (Vector3) (0.6f * (Vector2) toOuter));
float angle = Vector2.Angle(toOuter, player.gameObject.transform.position - gameObject.transform.position); float angle = Vector2.Angle(toOuter, colliderToPlayer);
if ( (angle > 90) && colliderToPlayer.magnitude < 1) { if ( angle < 90) {
Debug.Log("Player is on the outside! Angle: " + angle); Debug.Log("Player is on the outside! Angle: " + angle);
return; return;
} }

View file

@ -386,8 +386,4 @@ public class GameController : MonoBehaviour {
public void Continue() { public void Continue() {
ChangeState(GameState.RUNNING); ChangeState(GameState.RUNNING);
} }
public Player GetPlayer() {
return player;
}
} }