private static IEntity CreateKnight(int playerNumber) { IEntity entity = new Entity("Knight", UnitTypes.Ground, playerNumber); TargetDetector targetDetector = new TargetDetector(entity) { TargetTypes = UnitTypes.Ground | UnitTypes.Building, Range = 2 }; entity.AddComponent(targetDetector); MoveComponent mover = new MoveComponent(entity) { Speed = 2 }; entity.AddComponent(mover); HealthComponent health = new HealthComponent(entity, 100); entity.AddComponent(health); return(entity); }
protected override void Awake() { base.Awake(); playerDetector = GetComponentInChildren<TargetDetector>(); damageDetector = GetComponentInChildren<DamageDetector>(); animator = GetComponent<Animator>(); }
private void AddOwnershipToProjectile(GameObject projectile) { if (projectile.tag.Equals(GameTags.Projectile.ToString())) { TargetDetector detector = projectile.GetComponent <TargetDetector>(); detector.SetOwnerId(m_spawnOwnerCollider2D.GetInstanceID()); } }
void Awake() { _rigidbody = GetComponent <Rigidbody2D>(); _joystick = FindObjectOfType <VariableJoystick>(); _targetDetector = GetComponent <TargetDetector>(); _healthController = GetComponent <HealthController>(); _deathScreenController = FindObjectOfType <DeathScreenController>().gameObject; }
void Start() { cam = Camera.main; rb = GetComponent <Rigidbody>(); anim = GetComponent <Animator>(); detector = GetComponentInChildren <TargetDetector>(); _speed = walkSpeed; }
private void Awake() { patrol = GetComponent <Patrol>(); targetDetector = GetComponent <TargetDetector>(); chase = GetComponent <Chase>(); attack = GetComponent <Attack>(); animator = GetComponent <Animator>(); attack.enabled = false; animator.SetBool("isLookingForEnemies", true); }
void Start() { _targetDetector = gameObject.GetComponent <TargetDetector>(); _targetDetector.XTargetHit = XTargetHitDetected; _targetDetector.YTargetHit = YTargetHitDetected; _targetDetector.ZTargetHit = ZTargetHitDetected; _txtXRange.text = "Range: " + _targetDetector.XRange; _txtYRange.text = "Range: " + _targetDetector.YRange; _txtZRange.text = "Range: " + _targetDetector.ZRange; }
//Update the Influence map void UpdateMap() { //Loop throught the unfiltered map and decrease its value depending on the time since last frame. for (int y = 0; y < size; y++) { for (int x = 0; x < size; x++) { if (Unfiltered[x, y] > 0.0f) { Unfiltered[x, y] -= 1.0f * (Time.deltaTime / decreasetime); } else { Unfiltered[x, y] = 0.0f; } } } //Get the position of the player i world coordinates and Normal coordinates Vector3 pos = player.transform.position; Vector2 NormalPos = World2Normal(pos); //Set the position of the player in the influence map to 1.0. Unfiltered[(int)(NormalPos.x * size), (int)(NormalPos.y * size)] = 1.0f; TargetDetector script = GetComponent <TargetDetector>(); //Loop through all positions in the influence map and //check if they are inside the view radius and view angle of the agent for (int y = 0; y < size; y++) { for (int x = 0; x < size; x++) { Vector3 WorldPos = Indices2World(x, y); if (Vector3.Distance(transform.position, WorldPos) < script.viewRadius) { if (Vector3.Angle(transform.forward, WorldPos - transform.position) < script.viewAngle / 2) { //If the position is inside the agents view then a simple raycast is made to check if any obstacle is in the way if (!Physics.Raycast(transform.position, WorldPos - transform.position, Vector3.Distance(transform.position, WorldPos), script.ObstacleMask)) { //if position is visable then the position will get a value greater than 0 Unfiltered[x, y] = Mathf.Min(Unfiltered[x, y] + 1.0f - Mathf.Pow(Vector3.Distance(transform.position, WorldPos) / script.viewRadius, 2), 1.0f); } } } } } }
public MovementPackage GetDestinationFromFirstMove(float distanceScalar, Vector2 moveDirection) { var unit = TargetDetector.GetValidUnitInFrontFromTargetPosition(null, distanceScalar, moveDirection, _transform.position, 0.7f); var destination = EvaluateStartingMove(unit, distanceScalar, moveDirection); if (Vector2.Distance(_transform.position, destination.TargetLocation) < 0.1f) { return(null); } var startingPackage = new MovementPackage(_transform, destination, distanceScalar); return(startingPackage); }
private void Start() { InputHandler.OnTapEvent += OnTap; InputHandler.OnSwipeUpEvent += OnSwipeUp; InputHandler.OnSwipeDownEvent += OnSwipeDown; InputHandler.OnSwipeLeftEvent += OnSwipeLeft; InputHandler.OnSwipeRightEvent += OnSwipeRight; InputHandler.OnHoldEvent += OnHold; mHipTransform = transform.GetChild(0); mAnimator = GetComponent <Animator>(); mInitPlayerPosition = transform.position; TargetDetector = GetComponentInChildren <TargetDetector>(); HitDetector = GetComponentInChildren <HitDetector>(); }
void UpdateMap() { //Get variable from the player Vector3 pos = player.transform.position; Vector2 NormalPos = World2Normal(pos); TargetDetector script = player.GetComponent <TargetDetector>(); RaycastHit Hitpoint; //Loop thorugh the size of the map for (int y = 0; y < size.y; y++) { for (int x = 0; x < size.x; x++) { Vector3 WorldPos = Indices2World(x, y); //Check if the pos is outside of the view radius if (Vector3.Distance(player.transform.position, WorldPos) < script.viewRadius) { //Check if there is something that intersepts the ray from the agent to the pos. if (Physics.BoxCast(player.transform.position, player.GetComponent <Collider>().bounds.size, WorldPos - player.transform.position, out Hitpoint, player.transform.rotation, script.viewRadius, script.ObstacleMask)) { //Get the interseption point Vector2Int point = World2Indices(Hitpoint.point); //Set the point in the index to unwalkable try { Map[point.x, point.y] = 0.0f; } catch (System.IndexOutOfRangeException ex) { Debug.Log(point); } //Set so the mesh is updated status = true; } else { //Make a box check in is node if (Physics.CheckBox(WorldPos, new Vector3(grid.nodeRadius, 0.001f, grid.nodeRadius), Quaternion.identity, script.ObstacleMask)) { Map[x, y] = 0.0f; status = true; } } } } } }
protected override void Awake() { base.Awake(); animator = GetComponent <Animator>(); foreach (TargetDetector targetDetector in GetComponentsInChildren <TargetDetector>()) { if (targetDetector.name == "Near player detector") { #if DEBUG if (nearPlayerDetector != null) { Debug.LogError("[Guard] Double allocation to nearPlayerDetector."); } #endif nearPlayerDetector = targetDetector; } else if (targetDetector.name == "Far player detector") { #if DEBUG if (farPlayerDetector != null) { Debug.LogError("[Guard] Double allocation to farPlayerDetector."); } #endif farPlayerDetector = targetDetector; } #if DEBUG else { Debug.LogError("[Guard] Unknown target detector : " + targetDetector.name); } #endif } #if DEBUG if (nearPlayerDetector == null) { Debug.LogError("[Guard] nearPlayerDetector is not allocated."); } if (farPlayerDetector == null) { Debug.LogError("[Guard] farPlayerDetector is not allocated."); } #endif }
public void Tick() { if (!_playerMover.CurrentMoveDirection.HasValue) { return; } var size = Physics2D.OverlapCircleNonAlloc(_mover.transform.position, .5f, _enemyResults, _enemyMask); if (size <= 0) { return; } for (var i = 0; i < size; i++) { var unit = _enemyResults[i].GetComponent <IUnit>(); if (unit == null || unit.KillHandler.KillPoint.HasValue || _validCollisions.Contains(unit)) { continue; } if (!TargetDetector.DotProductSuccess(unit, _playerMover.CurrentMoveDirection.Value, 0.99f)) { if (!_invalidCollisions.Contains(unit)) { _invalidCollisions.Add(unit); OnInvalidEnemyCollision?.Invoke(3); } continue; } _validCollisions.Add(unit); unit.KillHandler.SetKillPoint(); } }
public MovementPlan RequestStartPlan(Vector2 inputDirection, float moveAmount) { var unit = TargetDetector.GetValidUnitInFrontFromTargetPosition(null, moveAmount, inputDirection, _player.transform.position, 0.7f); return(_movementPlanner.GetStartingPlan(inputDirection, unit)); }
// Use this for initialization void Start() { Current = (int)State.Search; fow = GetComponent <TargetDetector>(); mov = GetComponent <Movement>(); }
void Awake() { _targetDetector = GetComponent <TargetDetector>(); _healthController = GetComponent <HealthController>(); _enemySpawner = FindObjectOfType <EnemySpawner>(); }
protected override void Init() { base.Init(); detector = GetComponent <TargetDetector>(); targets = new List <Transform>(); }