nearest raycast hit across enemy cols

This commit is contained in:
ethan merchant 2024-12-16 07:15:31 -05:00
parent bc79d08bbd
commit 8113b3c567

View file

@ -165,26 +165,41 @@ static class Arts
if (true) // hit test
{
Vec3 hit_delta = rvolv_ori.Inverse * (enemy_pos - rvolv_pos);
float flat_z = hit_delta.z;
hit_delta.z = 0;
float hit_mag = hit_delta.Magnitude;
bool hit = hit_mag < enemy_rad;
Matrix enemy_m4 = enemy_test.pose.ToMatrix();
Ray local_ray = enemy_m4.Inverse.Transform(ray);
bool hit = false;
float min_dist = float.MaxValue;
Vec3 min_hit_pos = Vec3.Zero;
for (int i = 0; i < enemy_test.cols.Count; i++)
{
Sphere col = enemy_test.cols[i];
Vec3 hit_pos = Vec3.Zero;
if (col.Intersect(local_ray, out hit_pos))
{
float hit_dist = Vec3.Distance(hit_pos, local_ray.position);
if (hit_dist < min_dist)
{
hit = true;
min_dist = hit_dist;
min_hit_pos = hit_pos;
}
}
}
min_hit_pos = enemy_m4.Transform(min_hit_pos);
if (hit)
{
float hit_dist = flat_z + (Maths.smooth_stop((enemy_rad - hit_mag) / enemy_rad) * enemy_rad);
Vec3 hit_pos = rvolv_pos + rvolv_ori * V.XYZ(0, 0, hit_dist);
Mesh.Sphere.Draw(
mat_unlit,
Matrix.TS(
hit_pos,
min_hit_pos,
4 * U.cm
),
Color.White
);
if (Rig.btn_select.delta == +1)
{
VFX.Play(hit_pos);
VFX.Play(min_hit_pos);
}
}
}