You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
986 B
36 lines
986 B
using Enemies.States; |
|
using UnityEngine; |
|
|
|
namespace Enemies |
|
{ |
|
public class PathState : IState |
|
{ |
|
private readonly Enemy context; |
|
|
|
public PathState(Enemy context) |
|
{ |
|
this.context = context; |
|
} |
|
|
|
public void Enter() |
|
{ |
|
Debug.Log("Entering Path State"); |
|
context.currentState = Enemy.States.Path; |
|
} |
|
|
|
public void Execute() |
|
{ |
|
//Determine direction to target |
|
Vector2 direction = context.target.transform.position - context.transform.position; |
|
|
|
//Move in desired direction |
|
context.GetComponent<Rigidbody2D>().MovePosition((Vector2)context.transform.position + direction.normalized * context.speed * Time.deltaTime); |
|
float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg; |
|
context.transform.rotation = Quaternion.Euler(0, 0, angle); |
|
} |
|
|
|
public void Exit() |
|
{ |
|
} |
|
} |
|
} |