These forums are CLOSED. Please visit the new forums HERE
How to measure distance travelled? |
|
|
Nichiren Dinzeo
Registered User
Join date: 14 Feb 2007
Posts: 203
|
10-07-2009 16:39
I like to sail and I would like to start tracking the distance I have sailed. Any idea how this could be done?
|
|
Nichiren Dinzeo
Registered User
Join date: 14 Feb 2007
Posts: 203
|
let me clarify
10-07-2009 17:41
I can handle the posting to an external db the xyz and do all the calculations. I am just wandering how one would actually measure it. I think it would be as easy as posting xyz cords every so often and then doing some simple math.
maybe not. |
|
Somatika Xiao
Cyan Energy Man
Join date: 30 Jun 2006
Posts: 137
|
10-07-2009 18:41
No need for a DB, you can do something even easier.
float total_distance; vector old_pos; vector new_pos; default { on_rez(integer start_param) { new_pos = llGetPos(); old_pos = new_pos; llSetTimerEvent(2); } state_entry() { new_pos = llGetPos(); old_pos = new_pos; llSetTimerEvent(2); } timer() { vector new_pos = llGetPos(); total_distance += llVecDist(old_pos, new_pos); old_pos = new_pos; llSetText("Total Distance Traveled: " + (string)llFloor(total_distance), <1,1,1>, 0. ; // Set total distance} changed(integer change) { if(change & CHANGED_REGION) { new_pos = llGetPos(); old_pos = new_pos; } } } Feel free to use this code as an example, and please note I have not tested (Will in a few minutes!) and was done on the fly. (EDITED TO FIX CODE) (Second Edit, added region change & replaced method of position retrieval due to thinking it would not work on physical objects, but that is llSetPos got it mixed up.) _____________________
Peace & Prosperity
Somatika |
|
Nichiren Dinzeo
Registered User
Join date: 14 Feb 2007
Posts: 203
|
10-07-2009 18:47
wow...great! thanks...I will give it a try tonight and see if I can debug if needed.
I still plan on logging in db. I would like to keep track of all the stats over time. |
|
Nichiren Dinzeo
Registered User
Join date: 14 Feb 2007
Posts: 203
|
10-07-2009 19:11
seems to work as is. well done ! thx
|
|
Sindy Tsure
Will script for shoes
Join date: 18 Sep 2006
Posts: 4,103
|
10-07-2009 19:12
/me is curious why you're using llGetObjectDetails instead of llGetPos or llGetRootPosition..
edit: and I think you need a changed event for crossing sim lines.. _____________________
Sick of sims locking up every time somebody TPs in? Vote for SVC-3895!!!
- Go here: https://jira.secondlife.com/browse/SVC-3895 - If you see "if you were logged in.." on the left, click it and log in - Click the "Vote for it" link on the left |
|
Jig Chippewa
Fine Young Cannibal
Join date: 30 Oct 2006
Posts: 5,150
|
10-07-2009 22:27
"And I have miles to go before I sleep
And I have miles to go before I sleep." _____________________
Fine Young Cannibal
|