Skip to content

Commit 98bf017

Browse files
Fixing offroad logic
1 parent 321e422 commit 98bf017

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

pufferlib/ocean/drive/drive.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1279,7 +1279,7 @@ void compute_agent_metrics(Drive* env, int agent_idx) {
12791279
corners[i][0] = agent->x + (offsets[i][0]*half_length*cos_heading - offsets[i][1]*half_width*sin_heading);
12801280
corners[i][1] = agent->y + (offsets[i][0]*half_length*sin_heading + offsets[i][1]*half_width*cos_heading);
12811281
}
1282-
1282+
float buffer = 0.5f; // 0.5m buffer for offroad checking
12831283
GridMapEntity entity_list[MAX_ENTITIES_PER_CELL*25]; // Array big enough for all neighboring cells
12841284
int list_size = checkNeighbors(env, agent->x, agent->y, entity_list, MAX_ENTITIES_PER_CELL*25, collision_offsets, 25);
12851285
for (int i = 0; i < list_size ; i++) {
@@ -1291,6 +1291,7 @@ void compute_agent_metrics(Drive* env, int agent_idx) {
12911291
// Check for offroad collision with road edges
12921292
if(entity->type == ROAD_EDGE) {
12931293
int geometry_idx = entity_list[i].geometry_idx;
1294+
if(entity->traj_z[geometry_idx] > agent->z + buffer || entity->traj_z[geometry_idx] < agent->z - buffer) continue; // Edge is at a different z level
12941295
float start[2] = {entity->traj_x[geometry_idx], entity->traj_y[geometry_idx]};
12951296
float end[2] = {entity->traj_x[geometry_idx + 1], entity->traj_y[geometry_idx + 1]};
12961297
for (int k = 0; k < 4; k++) { // Check each edge of the bounding box

0 commit comments

Comments
 (0)