Skip to content

Commit

Permalink
interaction with enemy fix, JadeElephant score fix
Browse files Browse the repository at this point in the history
  • Loading branch information
compix committed Mar 20, 2017
1 parent ccc7b07 commit 50d3c3a
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 4 deletions.
3 changes: 2 additions & 1 deletion Assets/Prefabs/Level/JadeElephant.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ MonoBehaviour:
interactionIconScale: 0.5
useInteractionRangeOnly: 0
ignoreRaycastVisibility: 0
ScoreValue: 200
ScoreValue: 1
collectionSound: {fileID: 0}
m_collectableName: Jade Elefant
isWinItem: 0
3 changes: 2 additions & 1 deletion Assets/Prefabs/Level/Neu/Jade_Elephant1.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,10 @@ MonoBehaviour:
interactionIconScale: 1
useInteractionRangeOnly: 0
ignoreRaycastVisibility: 0
ScoreValue: 0
ScoreValue: 1
collectionSound: {fileID: 0}
m_collectableName: Jade Elefant
isWinItem: 0
--- !u!135 &135001409748805150
SphereCollider:
m_ObjectHideFlags: 1
Expand Down
6 changes: 5 additions & 1 deletion Assets/Scripts/Game Logic/EnemyInteractable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,12 @@ IEnumerator StunRoutine(Interactor interactor) {
stunIndicatorDestroyComp = null;
}

public override bool CanInteract(Interactor interactor) {
return IsStunPossible(interactor);
}

public bool IsStunPossible(Interactor stunner) {
return Vector3.Angle(stunner.transform.forward, transform.forward) < m_backAngle &&
return Util.IsPointInFOV(stunner.position, position, -transform.forward, m_backAngle, Vector3.up) &&
m_cooldown.IsOver() && m_stunRoutine == null && stunner.GetComponent<ElephantMovement>().CanMove();
}

Expand Down
1 change: 1 addition & 0 deletions Assets/Scripts/Game Logic/Interaction/Interactable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@ void OnDrawGizmosSelected() {
}

public abstract void Interact(Interactor interactor);
public virtual bool CanInteract(Interactor interactor) { return true; }
}
2 changes: 1 addition & 1 deletion Assets/Scripts/Game Logic/Interaction/Interactor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ Interactable FindMinInteractable() {
// Find closest match (smallest degree to interactable)
foreach (Collider collider in colliders) {
var interactable = collider.GetComponent<Interactable>();
if (interactable == null || !collider.gameObject) {
if (interactable == null || !collider.gameObject || !interactable.CanInteract(this)) {
continue;
}

Expand Down
9 changes: 9 additions & 0 deletions Assets/Scripts/Utils/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,13 @@ public static Polar VectorToPolar(Vector3 v) {
float r = Mathf.Sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
return new Polar(r, Mathf.Asin(v.y / r), -Mathf.Atan2(v.x, v.z));
}

/**
* <summary>Checks if a given point is in the field of view of an object with a position and viewing direction.</summary>
*/
public static bool IsPointInFOV(Vector3 point, Vector3 position, Vector3 direction, float fieldOfViewInDeg, Vector3 projPlaneNormal) {
var dirP = Vector3.ProjectOnPlane(direction, projPlaneNormal);
var dP = Vector3.ProjectOnPlane(point - position, projPlaneNormal);
return Vector3.Angle(dirP, dP) <= fieldOfViewInDeg * 0.5f;
}
}

0 comments on commit 50d3c3a

Please sign in to comment.