Sonic and Sega Retro Message Board: Need Help with Programming Tidbits - Sonic and Sega Retro Message Board

Jump to content

Hey there, Guest!  (Log In · Register) Help
Page 1 of 1
    Locked
    Locked Forum

Need Help with Programming Tidbits Math stuff in the SPG...

#1 User is offline Light Matter 

Posted 13 November 2015 - 08:32 PM

  • Posts: 11
  • Joined: 23-August 14
  • Gender:Male
  • Project: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...

Xsp = Gsp*cos(angle);
Ysp = Gsp*-sin(angle);



and...

Xsp -= jmp*sin(angle);
Ysp -= jmp*cos(angle);



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 User is offline winterhell 

Posted 14 November 2015 - 03:17 AM

  • Posts: 1023
  • Joined: 16-October 10
  • Gender:Male
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.
This post has been edited by winterhell: 14 November 2015 - 03:31 AM

#3 User is offline Light Matter 

Posted 14 November 2015 - 05:33 AM

  • Posts: 11
  • Joined: 23-August 14
  • Gender:Male
  • Project:Making a Sonic the Hedgehog engine in Flash w/ AS3.

View Postwinterhell, on 14 November 2015 - 03:17 AM, said:

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.


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 User is online PixelMonkey 

Posted 14 November 2015 - 06:02 AM

  • Posts: 4
  • Joined: 02-May 13
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.

Page 1 of 1
    Locked
    Locked Forum

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users