Commit 62b83537 authored by Rahix's avatar Rahix 🦀
Browse files

colliders: Fix rectangle colliders not being positioned properly

The values passed to Cuboid::new() must be half extents and the position
of the collider must describe the center.  In SVG, rectangles are
described by the top left corner and full extents which was incorrectly
passed to the Cuboid::new() constructor.  Fix this.
parent e3d8b183
......@@ -36,7 +36,7 @@ impl Collider {
}
pub fn new_rect_collider(width: f32, height: f32) -> Collider {
let shape = shape::Cuboid::new(nalgebra::Vector2::new(width, height));
let shape = shape::Cuboid::new(nalgebra::Vector2::new(width / 2.0, height / 2.0));
let groups = pipeline::CollisionGroups::new();
Collider::new(shape::ShapeHandle::new(shape), groups)
......
......@@ -182,7 +182,8 @@ impl SvgLevel {
height,
} => {
let collider = colliders::Collider::new_rect_collider(*width, *height);
let position = components::Position::new(*x, *y);
// Position must be the center of the rectangle
let position = components::Position::new(x + width / 2.0, y + height / 2.0);
world.push((collider, position));
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment