Skip to content

Bevy_city traffic#23603

Draft
nuts-rice wants to merge 7 commits intobevyengine:mainfrom
nuts-rice:bevy_city_traffic
Draft

Bevy_city traffic#23603
nuts-rice wants to merge 7 commits intobevyengine:mainfrom
nuts-rice:bevy_city_traffic

Conversation

@nuts-rice
Copy link
Copy Markdown
Contributor

Objective

Solution

  • Adds TrafficLight and associated enums for LightPhase and LightColor.
  • TrafficLightMaterials and .glb asset
  • TrafficPlugin
  • fields in Car for handling traffic logic
  • apply_traffic_rules for querying roads, cars and traffic light states.
  • spawning logic for traffic lights at intersection

Testing

Right now it's feature gated and currently WIP.

  • Cars do stop, but they should at minimum distance from one another
  • light materials aren't showing on traffic light, it's just static gray pole rn
  • should add car turning and tracking of cars egress of intersection
    Tests could be done for traffic logic, cars keeping distance at stop, possibly turning.

Showcase

traffic_wip

@alice-i-cecile alice-i-cecile added A-Rendering Drawing game state to the screen A-ECS Entities, components, systems, and events C-Examples An addition or correction to our examples C-Benchmarks Stress tests and benchmarks used to measure how fast things are S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels Mar 31, 2026
@github-project-automation github-project-automation Bot moved this to Needs SME Triage in ECS Mar 31, 2026
@github-project-automation github-project-automation Bot moved this to Needs SME Triage in Rendering Mar 31, 2026
pub tree_large: Handle<Scene>,
pub path_stones_long: Handle<Scene>,
pub fence: Handle<Scene>,
#[cfg(feature = "traffic")]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My initial preference is to use a runtime toggle for this, not a feature flag. Make the case to me for why we should compile this out?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i was mostly doing it for conveince. I can add it as toggle in settings instead

license = "MIT OR Apache-2.0"

[features]
trace_tracy = ["bevy/trace_tracy"]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is adding this as a feature to our example in particular useful?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was trying to get tracing to work . I'll get rid of that

(TrafficLightColor::Green, TrafficLightPhase::Green) => &materials.green_on,
(TrafficLightColor::Green, _) => &materials.green_off,
};
commands
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be meaningfully slower than mutating the handle.

"GREEN_LIGHT" => TrafficLightColor::Green,
_ => continue,
};
commands.entity(descendant).insert(TrafficLightBulb {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto here: don't use commands when you could just mutate.

}
}

// Component/material for bulb
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment is unclear (and it should be a doc comment).

@IceSentry
Copy link
Copy Markdown
Contributor

I'm working on multiple changes that will heavily conflict with this. The traffic simulation I have planned is also pretty different to what you are doing here. I'm going to change how the hierarchy is spawned to make it much easier to work with and not make the cars children of roads.

Also, in general, I prefer keeping PRs small and focused so I would suggest making a separate PR that only adds the traffic lights without any simulation.

@cart cart closed this May 5, 2026
@github-project-automation github-project-automation Bot moved this from Needs SME Triage to Done in Rendering May 5, 2026
@github-project-automation github-project-automation Bot moved this from Needs SME Triage to Done in ECS May 5, 2026
@cart cart reopened this May 5, 2026
@github-project-automation github-project-automation Bot moved this from Done to Needs SME Triage in Rendering May 5, 2026
@github-project-automation github-project-automation Bot moved this from Done to Needs SME Triage in ECS May 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ECS Entities, components, systems, and events A-Rendering Drawing game state to the screen C-Benchmarks Stress tests and benchmarks used to measure how fast things are C-Examples An addition or correction to our examples S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged

Projects

Status: Needs SME Triage
Status: Needs SME Triage

Development

Successfully merging this pull request may close these issues.

4 participants