Christopher Omega
Oxymoron
Join date: 28 Mar 2003
Posts: 1,828
|
02-17-2004 18:19
Hey everyone  I thought Id share a neet utility function that has proven extremely useful to me when dealing with non-physical movement. setPos(vector dest) { float dist = llVecDist(dest,llGetPos()); vector prevPos; while(dist > 0) { prevPos = llGetPos(); llSetPos(dest); if(llGetPos() == prevPos) // Yipes! The object didnt move! Occurs with float error. { llSay(0,"Float error detected and recovered from."); return; // return from this function immediately. } dist = llVecDist(dest,llGetPos()); } }
This function is more useful then the common llSetPos() loop, since it has automatic error recovery, and only compares one float, reducing the chances of an error ever occuring. Enjoy  ==Chris
|
Tiger Crossing
The Prim Maker
Join date: 18 Aug 2003
Posts: 1,560
|
02-18-2004 07:08
Under what circumstances does the inner IF get executed? I haven't seen the object not move before. (Server side, that is. I've seen it not update on the client, but as far as the scripts could tell, the motion took place.) For reference, I use this: while ( llVecDist( llGetPos(), target_pos ) > 0.001 ) llSetPos( target_pos ); You've got me worried there's some glitch than can cause an llSetPos() to fail repeatedly. 
_____________________
~ Tiger Crossing ~ (Nonsanity)
|
Christopher Omega
Oxymoron
Join date: 28 Mar 2003
Posts: 1,828
|
02-19-2004 08:55
From: someone Originally posted by Tiger Crossing You've got me worried there's some glitch than can cause an llSetPos() to fail repeatedly. It helps in a situation where an object refuses to move to a designated position. One example I can think of is trying to move through a hill in the ground. The object simply gets stuck on the ground's surface, never continuing to move. The iteration then gets stuck, since the object cant move, which causes the script to get stuck in an infinite loop. With the error catching implimented, the object knows it is stuck, so it breaks out of the infinite loop. Basicly, what it checks for is if calling llSetPos() made the object move or not. In a good percentage of every situation, the error isnt encountered, but, as always, something always goes wrong that you dont think of  Also, if the object is within a certain tiny distance of its target, llSetPos() will sometimes ignore moving again, however, the value reported from llGetPos() is still not completely equal to the destination's vector (otherwise known as float error), so you get another infinite looping situation there. Someone could also impliment some kind of failsafe mechanism, instead of an immdiate return from the function, since occasionally, you code to 'expect' the object to arrive exactly at the position you specify. I just provided a kind of framework that can be used to impliment something like that.
|