Noob question about shared behaviour
⚓ Rust 📅 2025-07-28 👤 surdeus 👁️ 12Hi, I'm new at using Rust and as one of my projects I'm trying to create a basic physics engine based off of some old YouTube videos. These videos, however, aren't in Rust, and take an Object-Oriented approach.
I'm at the point that I want to create my second type of "collider", I have a sphere and now want to make a cuboid. Intersections between two colliders create an IntersectionData object. I want to be able to print data about the intersection from this object, and that worked fine when I had only one collider type:
impl IntersectData {
pub fn log_intersection(shape1: &BoundingSphere, shape2: &BoundingSphere) {...}
}
Now, I'm not sure how I can make it so that the function just takes a generic "collider" for shape1 and shape2. I've tried using Traits and Generics a bit but I must be doing it wrong somehow. Could someone walk me through it a bit? Thanks.
2 posts - 2 participants
🏷️ Rust_feed