don't click here

Need Help with Programming Tidbits

Discussion in 'Fangaming Discussion' started by Light Matter, Nov 14, 2015.

  1. Light Matter

    Light Matter

    Member
    11
    0
    0
    Making a Sonic the Hedgehog engine in Flash w/ AS3.
    In Merqury's Sonic Physic's Guide, in the Solid Tiles section, there are a few lines of code like...

    Code (Text):
    1.  
    2. Xsp = Gsp*cos(angle);
    3. Ysp = Gsp*-sin(angle);
    4.  
    and...

    Code (Text):
    1.  
    2. Xsp -= jmp*sin(angle);
    3. Ysp -= jmp*cos(angle);
    4.  
    How would I calculate angle? I've been using for() loops as detectors at x-10 and x+10 like the guide said, but how do I find the angle with these 2 points? Help would be greatly appreciated.

    Also, on an unrelated note, how would one request a username change? Thanks.
     
  2. winterhell

    winterhell

    Member
    1,165
    7
    18
    To calculate the angle/slope between 2 points you use Atan2(y,x); angle = Atan2(y2 - y1, x2 - x1);
    Be advised that you might need to swap 1 and 2 around or negate values depending if the positive Y axis goes upwards or downwards. Well if things are off you'll see immediately on your sprite rotation. You need to see visually if the calculated angle is correct, right?
    Also you need to check if your math functions work in Radians or Degrees ("one radian is just under 57.3 degrees").
    Its quite possible the math functions output radians but the rendering functions for sprite angles take degrees so you'd need to convert between them.
    Btw in the classics, the angles for the tiles are preset in the data, they are not computed on the fly.
    Hope this helps.
     
  3. Light Matter

    Light Matter

    Member
    11
    0
    0
    Making a Sonic the Hedgehog engine in Flash w/ AS3.
    That was amazingly helpful, however, what do I write in for x1 and x2? If y1 and y2 are the values for the detectors for the angle, what are x1 are x2? I'm stumped. I'm prolly just being stupid, but I need the help. Also, I was using this to make an engine in Flash, and I'm going to be calculating angles on the fly for the actual physics. If you have Flash, I can send you a .FLA of the work, and you can investigate it yourself. You wouldn't steal it, right? Then again, why would you steal it? It's prolly shit. Thanks anyway.
     
  4. PixelMonkey

    PixelMonkey

    Member
    9
    0
    1
    If y1 and y2 are the y coordinates of the sensors, then x1 and x2 are their x coordinates. In this case, I guess it'd just be x+10 and x-10 from the player, as you mentioned above.