improve ray plane collision check

This commit is contained in:
Tuomas Katajisto 2025-09-15 22:19:46 +03:00
parent 3797a94aae
commit 00a4f37a33

View File

@ -42,14 +42,13 @@ Ray_Collision :: struct {
// At which 2D XZ point does a ray hit the ground plane at a height of // At which 2D XZ point does a ray hit the ground plane at a height of
// plane_height. Used for the level editor and maybe later the trile editor as well. // plane_height. Used for the level editor and maybe later the trile editor as well.
ray_plane_collision_point :: (ray: Ray, plane_height: float) -> Vector2 { ray_plane_collision_point :: (ray: Ray, plane_height: float) -> (bool, Vector2) {
// @ToDo: This is stupid, but I don't feel like bothering to do this correctly right now... dist_to_plane := ray.origin.y - plane_height;
collision_cube : Collision_Cube = .{ if ray.direction.y >= 0 then return false, .{0,0};
.{-100000, plane_height, -100000}, multi := dist_to_plane / abs(ray.direction.y);
.{100000, plane_height + 0.001, 100000} ray_to_plane := ray.direction * multi;
}; planePoint := ray_to_plane + ray.origin;
collision := does_ray_hit_cube(ray, collision_cube); return true, .{planePoint.x, planePoint.z};
return .{collision.point.x, collision.point.z};
} }
// Ported over from Raylib. // Ported over from Raylib.