using System.Collections; using System.Collections.Generic; using UnityEngine; public class PushAgent : AreaAgent { public GameObject goalHolder; public GameObject block; public override void InitializeAgent() { base.InitializeAgent(); } public override List CollectState() { List state = new List(); Vector3 velocity = GetComponent().velocity; Vector3 blockVelocity = block.GetComponent().velocity; state.Add((transform.position.x - area.transform.position.x)); state.Add((transform.position.y - area.transform.position.y)); state.Add((transform.position.z + 5 - area.transform.position.z)); state.Add((goalHolder.transform.position.x - area.transform.position.x)); state.Add((goalHolder.transform.position.y - area.transform.position.y)); state.Add((goalHolder.transform.position.z + 5 - area.transform.position.z)); state.Add((block.transform.position.x - area.transform.position.x)); state.Add((block.transform.position.y - area.transform.position.y)); state.Add((block.transform.position.z + 5 - area.transform.position.z)); state.Add(velocity.x); state.Add(velocity.y); state.Add(velocity.z); state.Add(blockVelocity.x); state.Add(blockVelocity.y); state.Add(blockVelocity.z); return state; } public override void AgentStep(float[] act) { reward = -0.01f; int movement = Mathf.FloorToInt(act[0]); MoveAgent(movement); if (gameObject.transform.position.y < 0.0f || Mathf.Abs(gameObject.transform.position.x - area.transform.position.x) > 8f || Mathf.Abs(gameObject.transform.position.z + 5 - area.transform.position.z) > 8) { done = true; reward = -1f; } } public override void AgentReset() { transform.position = new Vector3(Random.Range(-3.5f, 3.5f), 1.1f, -8f) + area.transform.position; GetComponent().velocity = new Vector3(0f, 0f, 0f); area.GetComponent().ResetArea(); } public override void AgentOnDone() { } }