Vector to angle question.

The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
edited August 2013 in Working with GS (Mac)
Okay so I'm a wiz at logic but I suck at vector math. I have an actor that rotates 360*. I have a second actor attached to it with an offset. I need the attached object to move with the main object as it rotates. Thanxs in advance to the math wiz!

Comments

  • jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408
    I'm sure someone will post something sooner. But I have code for this at home. Ill post it tonight
  • Braydon_SFXBraydon_SFX Member, Sous Chef, Bowlboy Sidekick Posts: 9,273
    The attached actor moves (with offset) and rotates with the first actor?
  • LumpAppsLumpApps Member Posts: 2,881
    edited August 2013
    In the orbitting actor:
    constrain selfposition.X to
    mainactor position X + (offset * cos(angle.mainactor))

    constrain selfposition.Y to
    mainactor position Y + (offset * sin(angle.mainactor))

    Hope that helps. It came out my head so not sure if I made a mistake ;)

    edit: if you want the orbiting actor to rotate too simply constrain its rotation to the rotation of the main actor (add a value like for example +45 if the initial is incorrect)

    edit2: Turned around the cos and sin ;)
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    edited August 2013
    @LudwigHeijden Will test it out. At first clance it looks correct.
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    edited August 2013
    Close it works but goes the opposite way...lol Oh I have that already. Totally had a brain fart about that!
  • LumpAppsLumpApps Member Posts: 2,881
    LOL
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    ahhh still not working right. It's not implimenting the offset. the X offset is 0. it's the Y I have +130 pixels
  • LumpAppsLumpApps Member Posts: 2,881
    With offset you mean radius right?
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    I think you had the sin and cos right the first time. I switched them back after looking at another formula I had. It works but when the main actor moves clockwise the second one moves counter clockwise.
  • LumpAppsLumpApps Member Posts: 2,881
    You will love this one: (see attachment)
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    Ah will look but I figured it.. Yaaaa good for the vector math dunce #:-S

    Here it is

    Actor one X - magnitude (OffsetX,OffsetY)*sin((Actor.one.Rotation)-atan(offsetX/offsetY))

    Actor one Y + magnitude (OffsetX,OffsetY)*cos((Actor.one.Rotation)-atan(offsetX/offsetY))

    Now on to the next puzzle but I think I have that formula getting it to move in that vector lane up and down.
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    edited August 2013
    @FryingBaconStudios -- I'd suggest using the equations in @LudwigHeijden's demo instead of the ones you posted. I feel kinda responsible for the equations you posted. I suggested those equations when I was a young pup. But they are not as generalizable as Ludwig's.

    I thought I had put something like this in the "Spare Code" discussion. But I can't find it there. Here it is. The 'code' is comparable to Ludwigs. But my graphics are not nearly as nice.

    http://www.mediafire.com/download/zpgd9040t34z3be/FerrisWheel.zip
Sign In or Register to comment.