public override void AgentAction(float[] vectorAction, string textAction) { // var pos = transform.position; /* * transform.Rotate(transform.up * vectorAction[1], Time.fixedDeltaTime * 200f); * rbody.AddForce(transform.forward * vectorAction[0] * speed, * ForceMode.VelocityChange);*/ // The agent give as output a position relative to his own /* * if (vectorAction.Any(value => value != 0.0f)) * { * // print($"Moving at { vectorAction[0] } - { vectorAction[1] }"); * // Only call if moving * movement.MoveTo(new Vector3(pos.x + vectorAction[0], pos.y + vectorAction[1], pos.z + vectorAction[2])); * // movement.MoveTo(new Vector3(pos.x + vectorAction[0], pos.y, pos.z + vectorAction[1])); * } * else * { * movement.Stop(); * }*/ // Rewards /* * var currentDistanceWithTarget = Vector3.Distance(transform.position, * target.position); * * // SetReward(Mathf.Clamp(currentDistanceWithTarget, 1, 0)); * AddReward(Mathf.Clamp(currentDistanceWithTarget, 1, 0)); * * // Reached target * if (currentDistanceWithTarget < 1.42f) * { * Done(); * } * * // Fell off platform * if (transform.position.y < 0) * { * Done(); * }*/ if (vectorAction[0] > 0.0f) // If he wanna throw ability { var position = target.position; var vec = new Vector3( position.x + Mathf.Clamp(vectorAction[1] * academy.agentPrecision, -academy.agentPrecision, academy.agentPrecision), position.y + Mathf.Clamp(vectorAction[2] * academy.agentPrecision, -academy.agentPrecision, academy.agentPrecision), position.z + Mathf.Clamp(vectorAction[3] * academy.agentPrecision, -academy.agentPrecision, academy.agentPrecision)); //print($"{vectorAction[1] * academy.agentPrecision}\n{vectorAction[1]}\n{academy.agentPrecision}\n{Mathf.Clamp(vectorAction[1] * academy.agentPrecision, -academy.agentPrecision,academy.agentPrecision)}"); attack.AttackNow(vec); } }
private void OnTriggerStay(Collider other) { // TODO: spawn the spell from the top of the tree or something like that (compare with renderer stuff) // var pos = new Vector3(other.transform.position.x, 20, other.transform.position.z); // if (Time.frameCount % 60 != 0) return; // Reduce lag, TODO: find better thing if (enemies.Any(other.CompareTag)) { attack.AttackNow(other.transform.position); } }
public override float Attack(out float attackEndToUse, float endurance, Transform target = null) { if (target == null) { attackEndToUse = 0f; return(-1f); } List <Attack> possibleAttacks; GetPossibleAttacks(endurance, out possibleAttacks); if (possibleAttacks.Count == 0f) { attackEndToUse = 0f; return(-1f); } Attack att = possibleAttacks[SM._rnd.Next(possibleAttacks.Count)]; dmgK = att.dmgK; string pr = projectiles[SM._rnd.Next(projectiles.Length)]; string[] forGolden = transform.GetComponent <SpriteRenderer>().sprite.name.Split(new char[] { '_' }); string golden = forGolden[forGolden.Length - 1] == "Golden" ? "_Golden" : ""; Transform RH = transform.parent.parent.Find("R_Hand"); GameObject proj = (GameObject)Instantiate((GameObject)Resources.Load("Soldier/S_Projectiles_" + pr + golden), new Vector3(RH.position.x, RH.position.y, RH.position.z), Quaternion.LookRotation(Vector3.forward, RH.up)); proj.transform.parent = RH; proj.GetComponent <Projectile_Weapon>().SetArmy(army); proj.GetComponent <Projectile_Weapon>().SetDmgK(dmgK); proj.gameObject.name = pr; pro = proj; Target = target; lastPos = Target.position + Vector3.forward * 0.3f; startTime = Time.time; float type = att.AttackNow(out attackEndToUse); attackEndToUse = attackEndToUse * weight; return(type); }
public override float Attack(out float attackEndToUse, float endurance, Transform target = null) { List <Attack> possibleAttacks; GetPossibleAttacks(endurance, out possibleAttacks); if (possibleAttacks.Count == 0f) { attackEndToUse = 0f; return(-1f); } Attack att = possibleAttacks[SM._rnd.Next(possibleAttacks.Count)]; dmgK = att.dmgK; lastAttack = Time.time; attackTime = att.attackTime; float type = att.AttackNow(out attackEndToUse); attackEndToUse = attackEndToUse * weight; return(type); }