So this bit of code has been giving me some trouble, even though it should be pretty straightforward. I'm trying to see how much room the player has on their left, and how much they have on their right, then move them toward the center of the corridor they're in when the two distances are too different.

Usually this works fine, but for some reason when I'm facing a wall and step toward it in some cases it just launches me either left or right. A panel shows my roomleft and roomright vars, and in the cases that it does this stepping toward the wall causes a drastic change even though the amount of room on my left and right hasn't changed in the slightest.

Could be a simple matter of using c_trace wrong, any insight would be greatly appreciated - I've been trying to work this out for 3 days now.

c_trace(my.x,vec_rotate(vector(0,5000,0),my.pan),IGNORE_ME | USE_BOX);
roomleft = vec_dist(my.x,hit.x);
c_trace(my.x,vec_rotate(vector(0,-5000,0),my.pan),IGNORE_ME | USE_BOX);
roomright = vec_dist(my.x,hit.x);
if (abs(roomleft - roomright) > 20 && roomleft < 400 && roomright < 400) c_move(me, vector(0,(roomleft-roomright)*time_step/8,0), NULL, USE_AABB);


"If it's true what you say to me, that the whole world will mourn his death - If the whole world will weep, I will give him back his breath."