= startPosition + Quaternion.Euler(Vector3.up * Random.Range(0f, 360f)) * Vector3.forward * 5f Reset platform position (5 meters away from the agent in a random direction) Transform.rotation = Quaternion.Euler(Vector3.up * Random.Range(0f, 360f)) Resetting the velocity is good practice with ML-Agents just in case the agent finds a way to fall through the floor /// We reset the agent position, turn it in a random direction, and reset its velocity. In this project, the episode ends when time runs out or when the coin is touched. Now add an override function called OnEpisodeBegin(). / Called once when the agent is first initialized This is called automatically by the Agent class and is intended for us to set up our agent. Private SimpleCharacterController characterController Īdd an override function called Initialize(). Rigidbody - a reference to the rigidbody for physics interactions StartPosition - we’ll keep track of the position of the agent when play starts, so that we can reset it thereĬharacterController - a reference to the SimpleCharacterController script attached to the character Platform - will give us access to the platform the coin will sit on and allow us to randomize the position Start by adding some variables at the top of the class. ![]() The remaining code will go between the curly brackets We’re going to build on top of that and override some functionality in this class. This contains a ton of functionality related to AI training and decision making. Note that we’re inheriting from the “Agent” class, which is part of the Unity.MLAgents package. Public class SimpleCollectorAgent : Agent Remove the existing code and replace it with the following Now that you have a character, we can write a new script that will control it.Ĭreate a new C# script called “SimpleCollectorAgent” It’s similar to creating a normal playable character in a game, but this one will be controlled by machine learning (hence the name ML-Agents). The Character is going to represent our Agent. Remove any existing colliders on the Coin and put a Sphere Collider on it. Make the Coin a child of the Platform, so that it moves around when the platform moves Mine is 0.5 m tall, 1 m wide, 1 m deep.Ĭreate a coin, by either using a Cylinder object in Unity or importing a 3d model, and place it on top of the Platform. I made a desert terrain in Blender.Ĭreate a box that the agent can jump on top of and call it “Platform”. You could use a Plane, or maybe you want to 3d model your own. Call it “CoinChallengeArea”.Īdd a flat surface that has a collider on it. ![]() Make a new Empty GameObject that will act as a parent for other objects in your challenge area. The Simple Character Controller tutorial is core to this project and will teach you how to make the 3D Platformer character that we use in this tutorial.Ĭheck out the ML-Agents Penguin tutorial here: Reinforcement Learning Penguins (Part 1/4) | Unity ML-Agents - Immersive LimitĬheck out the Simple Character Controller tutorial here: Simple Character Controller for Unity - Immersive Limit Create a Basic Challenge Area If you’ve done some ML-Agents before and understand how to train a basic agent, you can skip the Penguin tutorial. In order to keep this tutorial from being extremely long, I’m going to use a couple other free tutorials I’ve created previously as a foundation: “Penguins” and “Simple Character Controller”. In future tutorials, we’ll expand to multiple platforms/coins. To keep things really simple, this tutorial will only have one platform with a coin on it. ![]() This is inspired by games like Super Mario 64 and Super Mario 3D World where you explore the world, jumping on platforms to get coins. Here is what I have so far.In this tutorial, you’ll learn how to create a very simple 3D Platformer ML-Agent in Unity. I tried googling, other answers on here, and youtube and can’t seem to find one specific to my issue. What I am unable to figure out (and may not be possible) is rotating the capsule (to be replaced with a model later) to look in the direction he’s going. I can move left and right, and jump just fine so the actual movement is not at all an issue. I am using basic shapes at the moment, so a capsule with a character controller on it, and some cubes for the level. So I’m building a 3D (what I guess is 2.5D really) platformer but having a bit of trouble with the character control.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |