Hi Everybody,

in my ground distance calculator I do a simple while loop where I calculate the distance from my last known position to my actual position with <vector1> <function> <vector2> where <function> is set to "dist". In general this works fine, but after serveral thousands of kilometers it gives back a verctor like (1,1.012,0) instead of a distance in meters. I couldn't figure out why this happens. Sometimes it looks like it has something to do with tabbing out of the game and back in.

So my idea was now, just skip the calculation, when the result is something else than a float value. But i there any function in vizzy, which can get the data type?

Tags
Vizzy

4 Comments

  • Log in to leave a comment
  • Profile image
    120 Heady978

    @YaMomzBox420 you are very close to what I do. As program it is like:

    traveleddistance=0
    lastposition=position
    now
    while(true){
    traveleddistance=traveleddistance + format{0:f3}(lastpostion - positionnow)
    lastposition=position
    now
    }

    I didn't use round, as the craft always wobbles a little. So I used format{0:n3} to cut the number. But format{0:n3} adds a thousands separator. My new version with format{0:f3} doesn't add a thousands separator and works fine.

    The unexpected problem comes up, when you add two numbers, one without and one with a thousands separator. This results in a vector. For example you do 1200.5 + 1,200.5 = 2401.0 ... I would be fine with 2,401 or 2,401.0 or 2401 or 2401.0 but instead it results in vector(1, 200.5, 0) ... so it is not even a number anymore.

    3 months ago
  • Profile image
    1,176 YaMomzBox420

    What I'm suggesting would look something like:
    {round of({((position 1) - (position 2)) length}}

    The "round of" block also has sqrt and some other options like floor and ceiling which specifically round down or up respectively. With the exception of the variables, all these block are on the operators tab in vizzy. Hope this helps

    3 months ago
  • Profile image
    1,176 YaMomzBox420

    It would help if I knew a bit more about what you're trying to do, but I have a decent idea based off the context.

    You can store your current and previous position as variables in vizzy and update them with each timestep. Since both positions are a vector, you can subtract one from the other to get the vector that connects both points. If you place that vector into a {length()} block it will give you the exact distance from point to point in meters. This will have the same decimal problem as before, but you can use the {round()} block to get whole numbers only.

    It sounds like whatever you did works in a way, but it might not be the most efficient use of vizzy

    3 months ago
  • Profile image
    120 Heady978

    I've no answer to my question, but i found a solution for my problem, which might be helpful for others.
    My calculator just sums up the flown distance with the distance from last "checkpoint". Adding these numbers leads to a long value like 123456.789 with no group seperators(float/fixed point). As I dont want to count every single mm from every vibration and bouncing of the craft I formated my added values as "format{0:n3}". As my craft is now pretty fast there are cycles, where it made more than 1000 meters from last checkpoint and "format{0:n3}" gives something like 1,234.567
    Now doing 123456.789 + 1,234.567 does not simply give 124,691.356. It returns a vector like (1, 234.567, 0). This does not make sense at all, but thats what vizzy does.

    In the end I changed my calculation from 'n' to 'f' and it works.

    3 months ago

No Upvotes

Log in in to upvote this post.