ISSUES V2.0: angles still suck

@Monkeyman32123 Yeah, sorry about that. You know how it is: you say you’ll just tidy up in one corner and before you know it, you’ve cleaned the house from top to bottom.

The (anglerad - anglebet)%(2*math.pi) > math.pi is the bit I put the explanation about before the code.

I wish accidentally cleaning everything was a problem I had.
And yeah, I noticed that you explained it, it was just very…Mathey, and over my head at the time I posted that comment. Then, ironically enough, my math lesson today, while not about that at all, did give me one little bit of knowledge that made me understand it all.

Also, this may just be my eyes deceiving me, but to me it appears that the path is ever-so slightly oblong (only apparent when the circle gets larger). Being a perfectionist to the bone, and also being slightly disturbed that the pretty guide circle I added doesn’t always line up with the ship, I was wondering if this is just something I’ll have to live with or if there is in fact a simple fix?

@Monkeyman32123 Nice to know that maths’ classes are useful!

What behaviour do you want? Is it that when you have a lasso in action then the ship goes around the centre point in a perfect circle?

Yeah, I want it to be a perfect circle. I think I know how to do it, in a likely super-inefficient way, but, meh, it’d get the job done. Is there a reason the current way isn’t a perfect circle?

I think that the deviation from a true circle is coming from how you update the position. By doing shiploc = shipVelocity:rotate(angkerad) + shiploc rather than computing the position exactly then you get an error.

Imagine it like this. Stand at a point on a circle, facing tangentially to the circle. So the centre is at right angles to your direction. This is the direction the ship is facing in at this point. Now take a step forward. Are you still on the circle? No, you’re slightly outside it. The bigger the step, the further you are outside it.

The only way to get a true circle is to use sine and cosine to compute the exact position the ship should be at.

Okay, that’s what I thought -_- durn, reworking time! Maybe! I added a pretty effect that it’d be nice for it to line up for, but I’m not sure it deserves reworking the location updating. I like the simplicity as is

@Andrew_Stacey does 100 points plotted using ang=ang+3.6 and adding each point at vec2(0,dist):rotate(ang/(180/math.pi)) give the same results as

vec2(math.sin(ang/(180/math.pi))*dist,math.cos(ang/(180/math.pi))*dist)

Sorry about using (180/math.pi) so much in built functions don’t give me the same pleasure! Must be a huge turn off for a mathematician :-@

@Luatee - if you need to make it a little more efficient, you can write it as

local a=ang/(180/math.pi)
vec2(math.sin(a),math.cos(a))*dist

@Luatee Almost. The points go around the circle in a different direction. The vec2():rotate() points go anticlockwise, the vec2(math.sin(..)) points go clockwise.

An alternative would be:

local x,y = math.cos(2*math.pi/100), math.sin(2*math.pi/100)
local v = vec2(0,dist)
for i=1,100 do
    v = vec2(v.x * x - v.y * y, v.x * y + v.y * x)
    -- do something with v
end

Avoids having to compute the sine and cosine every time.

(@Ignatz This is the sort of thing I mean about “avoiding angles” wherever possible. We need the angle to compute the initial x and y, but once we’ve done that then we don’t need it again.)

@Ignatz Thank you :)>-

@Andrew_Stacey that’s some wizardry there, this will help a lot. There are a lot of parts to do with walking in my game that could be handled differently like this. Thanks!

And so my idiosyncratic inability to comprehend the inconceivably and painfully elementary topic of annular gyration swells to advanced unfamiliarity

@Monkeyman32123 It looks as though you’ve updated the code and problem in your first post. Can you confirm that? (I don’t want to go looking at the wrong code.)

Yes, I updated both the code and the problem in the original post so as to conserve space and such

@Monkeyman32123 That’s fine, just a good idea to make it clear that that’s what you’ve done. Not all of us speak “Sir Humphrey”.

I’ve tried running your code. It’s now quite different to how it was, so I’m not sure what of the behaviour that I see is desired and what is not. Can you describe what should happen?

Try replacing that commented section by:

shiploc = lasso + (shiploc - lasso):rotate(angleaddrad)

The problem (if this fixes it) was that you were updating shiploc based on the lasso relative to the ship. You should have been updating based on the ship relative to the lasso.

Using your code, it would be:

local offset = shiploc - lasso
local anglebet = math.atan2(offset.y,offset.x)
anglebet = anglebet + angleaddrad
shiploc.x = lasso.x + lassolength*math.cos(anglebet)
shiploc.y = lasso.y + lassolength*math.sin(anglebet)

(I do like the effects.)

Yeah, sorry, I was trying to make it simpler, I thought I put something in the original to say that it was different, but, oh well, I’ll get it next time :stuck_out_tongue:
And thanks, I knew it’d be something mind-numbingly simple >_<
My praise goes to Andrew_stacey for his innate skill with numbers! and his ability to make me feel silly in the best way possible :smiley:
And thanks, I worked hard on the effects :3