I'm trying to create a view system using markers in my game, in this example there are horizontal view markers(horviewmark)
which should make the view fallow the character's x coordinates and snap the view to a line between the markers. My real problem
lies in trying to return the id's of the nearest marker to the left and right. If I were to use the two nearest objects using instance_nth_nearest()
it would sometimes refer to two markers to one side, if the markers aren't perfectly placed. I am new to the 'do' statement, and all my efforts
in writing script have lead to glitches and crashes. My most recent attempt, much simpler than older ones, looks like this:
do
{if instance_nearest(pixeler.x, pixeler.y, horviewmark).x > pixeler.x && instance_nearest(pixeler.x, pixeler.y, horviewmark).x > instance_nth_nearest(pixeler.x, pixeler.y, horviewmark, viewskip).x or instance_nearest(pixeler.x, pixeler.y, horviewmark).x < pixeler.x && instance_nearest(pixeler.x, pixeler.y, horviewmark).x < instance_nth_nearest(pixeler.x, pixeler.y, horviewmark, viewskip).x
{view_yview = instance_nearest(pixeler.x, pixeler.y, horviewmark).y - (instance_nearest(pixeler.x, pixeler.y, horviewmark).y - instance_nth_nearest(pixeler.x, pixeler.y, horviewmark, viewskip).y)*(point_distance(pixeler.x, 0, instance_nearest(pixeler.x, pixeler.y, horviewmark).x, 0)/point_distance(pixeler.x, 0, instance_nth_nearest(pixeler.x, pixeler.y, horviewmark, viewskip).x, 0)/2) - view_hview/2}
else
{viewskip = viewskip + 1}}
until instance_nearest(pixeler.x, pixeler.y, horviewmark).x > pixeler.x && instance_nearest(pixeler.x, pixeler.y, horviewmark).x > instance_nth_nearest(pixeler.x, pixeler.y, horviewmark, viewskip).x or instance_nearest(pixeler.x, pixeler.y, horviewmark).x < pixeler.x && instance_nearest(pixeler.x, pixeler.y, horviewmark).x < instance_nth_nearest(pixeler.x, pixeler.y, horviewmark, viewskip).x
view_xview = pixeler.x - view_wview/2
pixeler is the name of the player
I know these are loooong lines it basically uses the variable viewskip to keep testing the next nearest viewmarker's x until it is greater or lesser than the nearest viewmarker depending on if pixeler(player)'s x is greater or lesser than the nearest. this crashes on me apparently
when the nearest marker shifts to another. I just scratched my other script today and wrote this one, so I assume the glitch in this code is pretty easy to see, but I think I have the wrong idea entirely of how to check the nearest left and right object.
thanks for the help in advance!











