Skip to content

Commit

Permalink
guard fov
Browse files Browse the repository at this point in the history
  • Loading branch information
mattheson committed Apr 24, 2024
1 parent 68e22ab commit 6946a2a
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 19 deletions.
7 changes: 4 additions & 3 deletions Assets/Scenes/SampleScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ Transform:
m_GameObject: {fileID: 31342188}
serializedVersion: 2
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: -0.01}
m_LocalPosition: {x: 0, y: 0, z: -0.0001}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
Expand All @@ -198,7 +198,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
layerMask:
serializedVersion: 2
m_Bits: 64
m_Bits: 256
startingAngle: 0
--- !u!23 &31342191
MeshRenderer:
Expand Down Expand Up @@ -389,6 +389,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 243570d553b454a36b8416c25e6d46e6, type: 3}
m_Name:
m_EditorClassIdentifier:
fieldOfView: {fileID: 31342190}
path: {fileID: 1935661233}
transforms: []
--- !u!195 &335417803
Expand Down Expand Up @@ -30572,7 +30573,7 @@ GameObject:
- component: {fileID: 1641776443}
- component: {fileID: 1641776442}
- component: {fileID: 1641776444}
m_Layer: 0
m_Layer: 8
m_Name: Player
m_TagString: Untagged
m_Icon: {fileID: 0}
Expand Down
3 changes: 0 additions & 3 deletions Assets/Scripts/FOV.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

public class FOV : MonoBehaviour
{
// Start is called before the first frame update
private Mesh mesh;
private float fov;
[SerializeField] private LayerMask layerMask;
Expand Down Expand Up @@ -60,8 +59,6 @@ void LateUpdate()

}



mesh.vertices = vertices;
mesh.uv = uv;
mesh.triangles = triangles;
Expand Down
21 changes: 17 additions & 4 deletions Assets/Scripts/Guard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

public class Guard : MonoBehaviour
{
[SerializeField] FOV fieldOfView;
[SerializeField] GameObject path;
NavMeshAgent agent;

Expand All @@ -14,22 +15,34 @@ public class Guard : MonoBehaviour

void Start()
{
agent = GetComponent<NavMeshAgent>();
agent = GetComponent<NavMeshAgent>();
agent.updateUpAxis = false;
agent.updateRotation = false;
transforms = path.GetComponentsInChildren<Transform>().ToList();
transforms.RemoveAt(0);
foreach (Transform t in transforms) {
foreach (Transform t in transforms)
{
Debug.Log(t);
}

Vector3 mouseWorldPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
// mouseWorldPos.z = 0f; // zero z
Vector3 aimDir = (mouseWorldPos - transform.position).normalized;
if (Input.GetKeyDown(KeyCode.Q))
{
fieldOfView.SetAimDirection(fieldOfView.startingAngle + 1);
}
}

void Update()
{
agent.SetDestination(transforms[transformIdx].position);
agent.SetDestination(transforms[transformIdx].position);
Vector3 offset = transform.position - transforms[transformIdx].position;
if (offset.magnitude <= 3) {
if (offset.magnitude <= 3)
{
transformIdx = (transformIdx + 1) % transforms.Count;
}
transform.position = new Vector3(transform.position.x, transform.position.y, 0);
fieldOfView.SetOrigin(transform.position);
}
}
8 changes: 0 additions & 8 deletions Assets/Scripts/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,6 @@ void Start()
// Update is called once per frame
void Update()
{
Vector3 mouseWorldPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
// mouseWorldPos.z = 0f; // zero z
Vector3 aimDir = (mouseWorldPos - transform.position).normalized;
if (Input.GetKeyDown(KeyCode.Q)){
fieldOfView.SetAimDirection(fieldOfView.startingAngle + 1);
}
fieldOfView.SetOrigin(transform.position);

}

void FixedUpdate() {
Expand Down
2 changes: 1 addition & 1 deletion ProjectSettings/TagManager.asset
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ TagManager:
- UI
- Objects
- Obstacles
-
- Player
-
-
-
Expand Down

0 comments on commit 6946a2a

Please sign in to comment.