Skip to content
Discussion options

You must be logged in to vote

I think the most close to orbit is moving sprite example but instead of just move up and down, you should use something like polar coordinate system

//! Renders a 2D scene containing a single, moving sprite.

use bevy::prelude::*;
use std::f32::consts::PI;

const ORBIT_CENTER: Vec3 = Vec3 {
    x: 100.0,
    y: 0.0,
    z: 0.0,
};

const ORBIT_RADIUS: f32 = 150.0;

// Negative is clockwise
// Positive is counterclockwise
// Currently half a turn per second counterclockwise
const ORBIT_SPEED: f32 = 0.5;

fn orbit_pos(mut angle: f32) -> Vec3 {
    angle *= ORBIT_SPEED;
    ORBIT_RADIUS * Vec3::new(angle.cos(), angle.sin(), 0.0)
}

fn main() {
    App::new()
        .add_plugins(DefaultPlugi…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by hblzr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants