- Home /
Enemies are moving aroung wildly
Hey I'm programming a shooter game, where the characters can only move to the x and z axis. So after a while, I think mostly when the enemies are respawned, the enemies are moving around wildly to the x and z axis. It is unintentionally. The Enemies have a Rigidbody. So don't know how to fix it. I'm using the ml-agent script so the code looks like this:
Vector3 dirToGo = Vector3.zero;
Vector3 rotateDir = Vector3.zero;
int action = Mathf.FloorToInt(act[0]);
// Goalies and Strikers have slightly different action spaces.
switch (action)
{
case 1:
dirToGo = transform.forward * 1f;
break;
case 2:
dirToGo = transform.forward * -1f;
break;
case 3:
rotateDir = transform.up * 1f;
break;
case 4:
rotateDir = transform.up * -1f;
break;
case 5:
dirToGo = transform.right * -0.75f;
break;
case 6:
dirToGo = transform.right * 0.75f;
break;
}
transform.Rotate(rotateDir, Time.fixedDeltaTime * 200f);
agentRB.AddForce(dirToGo * academy.agentRunSpeed, ForceMode.VelocityChange);
Answer by James_BadAlchemy · Dec 25, 2018 at 08:21 AM
Where are you running this? Custom method, Update, Fixed?
It's in the method: public override void AgentAction(float[] vectorAction, string textAction){}
It's a method of the ml-agents library. Called every step of the engine. Here the agent takes an action.
Your answer
Follow this Question
Related Questions
Character Jumping 2 Answers
Can't seem to use AddForce 2 Answers
Movement Relative to both Camera and XZ Plane 3 Answers
Top Down car/vehicle movement 1 Answer
AddForce to a randomly selected GameObject with a rigidbody 0 Answers