forked from RLBot/RLBotJavaExample
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathControlsOutput.java
More file actions
100 lines (78 loc) · 2.36 KB
/
ControlsOutput.java
File metadata and controls
100 lines (78 loc) · 2.36 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package rlbot;
import rlbot.api.GameData;
public class ControlsOutput {
// 0 is straight, -1 is hard left, 1 is hard right.
private float steer;
// -1 for front flip, 1 for back flip
private float pitch;
// 0 is straight, -1 is hard left, 1 is hard right.
private float yaw;
// 0 is straight, -1 is hard left, 1 is hard right.
private float roll;
// 0 is none, -1 is backwards, 1 is forwards
private float throttle;
private boolean jumpDepressed;
private boolean boostDepressed;
private boolean slideDepressed;
public ControlsOutput() {
}
public ControlsOutput withSteer(float steer) {
this.steer = clamp(steer);
return this;
}
public ControlsOutput withPitch(float pitch) {
this.pitch = clamp(pitch);
return this;
}
public ControlsOutput withYaw(float yaw) {
this.yaw = clamp(yaw);
return this;
}
public ControlsOutput withRoll(float roll) {
this.roll = clamp(roll);
return this;
}
public ControlsOutput withThrottle(float throttle) {
this.throttle = clamp(throttle);
return this;
}
public ControlsOutput withJump(boolean jumpDepressed) {
this.jumpDepressed = jumpDepressed;
return this;
}
public ControlsOutput withBoost(boolean boostDepressed) {
this.boostDepressed = boostDepressed;
return this;
}
public ControlsOutput withSlide(boolean slideDepressed) {
this.slideDepressed = slideDepressed;
return this;
}
public ControlsOutput withJump() {
this.jumpDepressed = true;
return this;
}
public ControlsOutput withBoost() {
this.boostDepressed = true;
return this;
}
public ControlsOutput withSlide() {
this.slideDepressed = true;
return this;
}
private float clamp(float value) {
return Math.max(-1, Math.min(1, value));
}
GameData.ControllerState toControllerState() {
return GameData.ControllerState.newBuilder()
.setThrottle(throttle)
.setSteer(steer)
.setPitch(pitch)
.setYaw(yaw)
.setRoll(roll)
.setBoost(boostDepressed)
.setHandbrake(slideDepressed)
.setJump(jumpDepressed)
.build();
}
}