closest object
Blitz3D Forums/Blitz3D Programming/closest object
| ||
| I found some similar examples but wondered if anyone can provide some simple code for the following. I want to use fixed camera pivots around my level. This I can achieve several ways so no issue. The problem is I want to be able to find the closest camerapivot to the player and position the camera there. Sort of like a realtime resident evil type effect. creating the pivots points is easy. positioning the single camera accordingly is easy. How do I mathematically calculate the nearest camerapivot. I bet its really simple, but I cant figure it without a ton of math. |
| ||
| Just go through the list of pivots and use http://www.blitzbasic.com/b3ddocs/command.php?name=EntityDistance&ref=3d_a-z to find out how far away they are. |
| ||
Assuming you have all the pivots parented to the level
NearestPivot = 0
NearestDistance# = 1000000
for c = 1 to countchildren( Level )
Pivot = getchild( Level, c )
distance# = entitydistance( player, Pivot )
if distance < NearestDistance
NearestDistance = distance
NearestPivot = Pivot
endif
next
entityparent camera, NearestPivot
positionentity camera, 0,0,0
pointentity camera, player
positionentity camera,player
;entityparent camera, 0
|
| ||
| Thanks stevie, i will test it out. I am thinking of using milkshape and positioning joints around the level to reference the camerapivot. I use this method a lot already to locate areas in the model so it should work. (I hope) |