-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathBot.cs
More file actions
57 lines (49 loc) · 2.56 KB
/
Bot.cs
File metadata and controls
57 lines (49 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System.Drawing;
using System.Numerics;
using Bot.Utilities.Processed.BallPrediction;
using Bot.Utilities.Processed.FieldInfo;
using Bot.Utilities.Processed.Packet;
using RLBotDotNet;
namespace Bot
{
// We want to our bot to derive from Bot, and then implement its abstract methods.
class Bot : RLBotDotNet.Bot
{
// We want the constructor for our Bot to extend from RLBotDotNet.Bot, but we don't want to add anything to it.
// You might want to add logging initialisation or other types of setup up here before the bot starts.
public Bot(string botName, int botTeam, int botIndex) : base(botName, botTeam, botIndex) { }
public override Controller GetOutput(rlbot.flat.GameTickPacket gameTickPacket)
{
// We process the gameTickPacket and convert it to our own internal data structure.
Packet packet = new Packet(gameTickPacket);
// Get the data required to drive to the ball.
Vector3 ballLocation = packet.Ball.Physics.Location;
Vector3 carLocation = packet.Players[Index].Physics.Location;
Orientation carRotation = packet.Players[Index].Physics.Rotation;
// Find where the ball is relative to us.
Vector3 ballRelativeLocation = Orientation.RelativeLocation(carLocation, ballLocation, carRotation);
// Decide which way to steer in order to get to the ball.
// If the ball is to our left, we steer left. Otherwise we steer right.
float steer;
if (ballRelativeLocation.Y > 0)
steer = 1;
else
steer = -1;
// Examples of rendering in the game
Renderer.DrawString3D("Ball", Color.Black, ballLocation, 3, 3);
Renderer.DrawString3D(steer > 0 ? "Right" : "Left", Color.Aqua, carLocation, 3, 3);
Renderer.DrawLine3D(Color.Red, carLocation, ballLocation);
// This controller will contain all the inputs that we want the bot to perform.
return new Controller
{
// Set the throttle to 1 so the bot can move.
Throttle = 1,
Steer = steer
};
}
// Hide the old methods that return Flatbuffers objects and use our own methods that
// use processed versions of those objects instead.
internal new FieldInfo GetFieldInfo() => new FieldInfo(base.GetFieldInfo());
internal new BallPrediction GetBallPrediction() => new BallPrediction(base.GetBallPrediction());
}
}