-
Hi all, I'm trying to use Bevy to create a 2D top-down style racing game. In order to generate the track, I'm using a set of I think I have getting the line's center position, which I can set at the translation, length, and the line's rotation along the z axis down, but the code I use for that is below just in case. let z_rot = ((self.1 - other.1) / (self.0 - other.0)).atan() * (180.0 / PI); // unit conversion: radians to euler degrees
let length = ((self.0 - other.0).powi(2) + (self.1 - other.1).powi(2)).sqrt();
let center_point = ((self.0 + other.0) / 2.0, (self.1 + other.1) / 2.0); This is the code I have so far for generating a line: fn from_len_deg(
pos: (f32, f32),
length: f32,
rot: f32,
color: Handle<ColorMaterial>,
meshes: &mut ResMut<Assets<Mesh>>
) -> bevy::prelude::SpriteBundle {
let mut transform = Transform::from_scale(Vec3::ONE);
transform.translation = Vec3::new(pos.0, pos.1, 0.0);
transform.rotation = Quat::from_rotation_z(rot);
let sprite = SpriteBundle {
material: color,
mesh: meshes.add(Mesh::from(shape::Quad { size: Vec2::new(length, 1.0), flip: false })),
sprite: Sprite::new(Vec2::new(length, 1.0)),
transform,
..Default::default()
};
sprite
} This sounds right in my head, but running it produces weird results. Here's what the points My guess is that the translation is not being updated properly, but inspecting the transforms during runtime by using the bevy-inspector-egui shows completely normal and expected values. Below is for the line from Frankly, I'm starting to feel at my wit's end here. Is there anything that jumps out as a logic fault in terms of how I'm attempting to create these? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hey guys, solved this myself by literally holding up a protractor to my screen and trial/erroring until something worked. A working-ish version is in this gist. |
Beta Was this translation helpful? Give feedback.
Hey guys, solved this myself by literally holding up a protractor to my screen and trial/erroring until something worked. A working-ish version is in this gist.
https://gist.github.com/tyush/07d72231e6f7cbe6fe9b6bc8c4e522f9