public override bool Update(MonoBehaviour behaviour, Sequencer.StateInstance state) { bool done = true; if (followPlayer && !state.IsDelayReached(followPlayerDuration)) { Entity ai = (Entity)behaviour; PlanetAttach pa = ai.planetAttach; AIState aiState = (AIState)state; Player player = SceneLevel.instance.player; aiState.curPlanetDir = pa.GetDirTo(player.planetAttach, followPlayerHorizontal); if (followPlayerHorizontal) { pa.velocity = new Vector2(Mathf.Abs(pa.velocity.x) * aiState.curPlanetDir.x, pa.velocity.y); } else { pa.velocity = aiState.curPlanetDir * pa.velocity.magnitude; } done = false; } return(done); }
public override void Start(MonoBehaviour behaviour, Sequencer.StateInstance state) { Entity ai = (Entity)behaviour; PlanetAttach pa = ai.planetAttach; AIState aiState = (AIState)state; if (accel > 0) { if (usePlayerDir) { Player player = SceneLevel.instance.player; aiState.curPlanetDir = pa.GetDirTo(player.planetAttach, horizontalOnly); } else if (!useDir) { aiState.curPlanetDir = Util.Vector2DRot(new Vector2(1, 0), angle * Mathf.Deg2Rad); } pa.accel = aiState.curPlanetDir * accel; } else { pa.accel = Vector2.zero; } }
public override void Start(MonoBehaviour behaviour, Sequencer.StateInstance state) { Entity ai = (Entity)behaviour; PlanetAttach pa = ai.planetAttach; Player player = SceneLevel.instance.player; ((AIState)state).curPlanetDir = pa.GetDirTo(player.planetAttach, horizontalOnly); }
public override bool Update(MonoBehaviour behaviour, Sequencer.StateInstance state) { AIState aiState = (AIState)state; Entity ai = (Entity)behaviour; PlanetAttach pa = ai.planetAttach; Player player = SceneLevel.instance.player; //Debug.Log("side: "+pa.CheckSide(player.planetAttach)); Vector2 prevDir = aiState.curPlanetDir; aiState.curPlanetDir = pa.GetDirTo(player.planetAttach, horizontalOnly); bool done = true; //cap speed on opposite dir if (Vector2.Dot(prevDir, aiState.curPlanetDir) < 0.0f) { if (useBreakSpeed) { pa.velocity = prevDir * breakSpeed; } if (doneAfterNumChangeDir > 0 && aiState.counter < doneAfterNumChangeDir) { aiState.counter++; } } if (doneAfterNumChangeDir > 0) { done = doneAfterNumChangeDir == aiState.counter && Vector2.Dot(pa.planetDir, aiState.curPlanetDir) > 0.0f; } //pa.velocity = Vector2.zero; pa.accel = aiState.curPlanetDir * accel; return(done); }
public override void Start(MonoBehaviour behaviour, Sequencer.StateInstance state) { Entity ai = (Entity)behaviour; PlanetAttach pa = ai.planetAttach; AIState aiState = (AIState)state; float speed = speedMin < speedMax?Random.Range(speedMin, speedMax) : speedMin; if (speed > 0) { if (followPlayer) { Player player = SceneLevel.instance.player; aiState.curPlanetDir = pa.GetDirTo(player.planetAttach, followPlayerHorizontal); } else if (!useDir) { aiState.curPlanetDir = Util.Vector2DRot(new Vector2(1, 0), angle * Mathf.Deg2Rad); } pa.velocity = aiState.curPlanetDir * speed; ai.action = Entity.Action.move; } else { pa.velocity = Vector2.zero; ai.action = Entity.Action.idle; } if (resetAccel) { pa.accel = Vector2.zero; } }