virtual public void act(GameObject actor) { GetEnemies(); //Calculate direction of enemies. Not used, as can result in non-positions /* * Vector3 enemyDirection = Vector3.zero; * * foreach(GameObject enemy in enemies) * { * Debug.Log(enemy.transform.position); * enemyDirection += enemy.transform.position - actor.transform.position; * } * * enemyDirection.Normalize(); * Steering.MoveTo(actor.transform, actor.transform.position + (enemyDirection * GameRules.MaxMovableDistance)); */ Steering.MoveTo(actor.transform, enemies[0].transform.position); /* * foreach (var enemy in sortedEnemiesByDist) { * float distToTarget = Vector3.Distance(enemy.transform.position, actor.transform.position); * * if (distToTarget > GameRules.MaxAttackRange) { * //TODO use A* algorithm * float distToMove = distToTarget - GameRules.MaxAttackRange; * * * } else if(IsValidTarget(actor, enemy)) { * //TODO attack * } * } */ }
public void act(GameObject actor) { //Calculate direction of enemies. Not used, as can result in non-positions. Should find nearest edge Vector3 enemyDirection = Vector3.zero; foreach (GameObject enemy in enemies) { enemyDirection += enemy.transform.position - actor.transform.position; } enemyDirection.Normalize(); Steering.MoveTo(actor.transform, actor.transform.position + (-enemyDirection * GameRules.MaxMovableDistance)); }
// Update is called once per frame void Update() { if (_currentHealth <= 0) { _currentHealth = 0; _alive = false; rigidbody.useGravity = true; rigidbody.constraints = RigidbodyConstraints.None; this.transform.Rotate(Vector3.forward, 1.5f); Steering.SetSteeringActive(this.transform, false); if (Team == Teams.Team1) { TurnManager.OnTeam1 -= NewTurn; } if (Team == Teams.Team2) { TurnManager.OnTeam2 -= NewTurn; } } if (Active) { _moveRangeEmitter.transform.position = this.transform.position; _attackRangeEmitter.transform.position = this.transform.position; if (_moving) { Steering.SetSteeringActive(this.transform, true); _leftMoveLength -= Vector3.Distance(this.transform.position, lastPos); lastPos = this.transform.position; _moveRangeEmitter.transform.localScale = new Vector3(_leftMoveLength * 2, 0.1f, _leftMoveLength * 2); if (_leftMoveLength <= 0 || Input.GetKeyDown(KeyCode.E)) { Steering.MoveTo(this.transform, this.transform.position); _leftMoveLength = 0; _moving = false; Steering.SetSteeringActive(this.transform, false); } Steering.SteeringUpdate(this.transform); } } }
public void MoveTo(Vector3 toPos) { Steering.SetSteeringActive(this.transform, true); toPos.y = this.transform.position.y; if (Vector3.Distance(this.transform.position, toPos) < _leftMoveLength) { Steering.MoveTo(this.transform, toPos); Debug.Log("Moving"); } else { Vector3 newTo = (toPos - this.transform.position).normalized; newTo *= _leftMoveLength; Steering.MoveTo(this.transform, toPos); Debug.Log("Too long"); } }
/// <summary> /// Causes the agent to make one step towards the object at objectPosition /// The speed of approach will reduce one this agent is within /// an ApproachRadius of the objectPosition /// </summary> /// <param name="agentToApproach"></param> public void Approach(SOFT152Vector objectPosition) { Steering.MoveTo(agentPosition, objectPosition, AgentSpeed, ApproachRadius); StayInWorld(); }
public void act(GameObject actor) { NicolaisCodeVirkerIkke = GameObject.Find("RUNAWAY"); //Calculate direction of enemies. Not used, as can result in non-positions. Should find nearest edge Steering.MoveTo(actor.transform, NicolaisCodeVirkerIkke.transform.position); }