Improved terrain collision slightly

This commit is contained in:
2018-07-01 19:10:09 -05:00
parent 5fa2843de2
commit 4c603c3a3d
2 changed files with 6 additions and 2 deletions

View File

@@ -39,7 +39,7 @@ class IMICFPS
smaller_list.each do |vert|
next if vert.nil?
if nearest
if Gosu.distance(vertex.x, vertex.z, vert.x, vert.z) < Gosu.distance(nearest.x, nearest.z, vert.x, vert.z)
if distance(vert, vertex) < distance(vert, nearest)
nearest = vert
end
end
@@ -49,6 +49,10 @@ class IMICFPS
return nearest
end
def distance(vertex, other)
return Math.sqrt((vertex.x-other.x)**2 + (vertex.y-other.y)**2 + (vertex.z-other.z)**2)
end
end
end
# class IMICFPS