- Home /
Question by
poopatyleesin · Oct 22, 2021 at 09:27 AM ·
targetartificial intelligenceagent
Target ML-Agents falling random down HELP PLS :(
Im trying to perform a simple AI using mlagents last version, everithing is fine with version python pytorch etc but i have an issue, after attaching the script and writing the basic movement istructions my target, witch should be static fall down the plane. and my agent try to catch with a self rotation.
This is my code for the Agent script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.MLAgents;
using Unity.MLAgents.Sensors;
using Unity.MLAgents.Actuators;
public class CorpFollowThief : Agent
{
[SerializeField ]private Transform thiefPosition;
public override void OnEpisodeBegin()
{
transform.position = new Vector3(0, 1, 2);
}
public override void CollectObservations(VectorSensor sensor)
{
sensor.AddObservation(transform.localPosition); //3 x y z
sensor.AddObservation(thiefPosition.localPosition); //3 x y z
}
public override void OnActionReceived(ActionBuffers actions)
{
float movementSpeed = 1f;
float moveX = actions.ContinuousActions[0];
float moveZ = actions.ContinuousActions[1];
transform.position += movementSpeed * Time.deltaTime * new Vector3(moveX, 0, moveZ);
}
public override void Heuristic(in ActionBuffers actionsOut)
{
ActionSegment<float> continuousAction = actionsOut.ContinuousActions;
continuousAction[0] = Input.GetAxisRaw("Horizontal");
continuousAction[1] = Input.GetAxisRaw("Vertical");
}
private void OnTriggerEnter(Collider other)
{
if(other.TryGetComponent<Thief>(out Thief thief))
{
SetReward(1f);
EndEpisode();
}
if (other.TryGetComponent<Wall>(out Wall wall))
{
SetReward(-1f);
EndEpisode();
}
}
}
cattura.png
(79.3 kB)
Comment
with ML agents your Ai might just fall down 100s of times before it starts to learn, you need to keep the tasks and rewards simple.
Your answer
