ClawHaMMer Posted September 7, 2008 Report Share Posted September 7, 2008 Hello guys, been lurking here for a while now and picking up information here and there - I've always been a big fan of sonic games since as was a kid and used to play fan games from way back before even static engines were around and people still used CC and TGF I found a very nice tutorial by Damizean a while back (it was here I believe: http://www.academiarpg.com/personal/damizean/tutorial) which went through all the basics of angle detection, jumping in the 360 engine and collisions etc. I was hoping to find something similar that someone could point me to or if Damizean had the tutorial stashed away somewhere that would be awesome! I realise alot of the basics are in the tutorial section in the form of GM and MMF files but I'm currently coding in blitz basic (2D) as I've been using that language for a few years, so was hoping for something which explains the concepts and from there I should be able to come up with code. At the moment I'm developing a sonic engine for fun, so far I have angle detection using the classic two points underneath the player and ground detection, but I'm curious about how current engines in use for modern fangames work with slopes (gaining/losing speed) and jumping. Also I'm not sure how to handle angles when in the air and how to apply gravity correctly. For now Im just setting the players angle to zero and using different counters for speed in air than speed on the ground but this presents problems, and I'm sure there will be a much neater, more efficient way of doing it. tl;dr - can I haz 360 tutorials plz??? Thanks for any help you can offer! Link to comment Share on other sites More sharing options...
Kain Posted September 7, 2008 Report Share Posted September 7, 2008 == Slope Gravity Acceleration == Acceleration from slope gravity is a simple trigonometric formula based on projection: -sin( angle - gravity_direction) * gravity; angle is the angle of Sonic where 0 = flat floor, etc. gravity_direction is the angle of the vector that gravity is pulling in (in general, it's 270 or 3*PI/2 meaning straight down) gravity is the acceleration from gravity in pixels / second^2. Although I believe it's generally multiplied by 0.8 to work well with the other accelerations (i.e. so it's not too powerful to run in loop-de-loops). You simply add that to your horizontal speed once per step and you got slope acceleration. == Jumping and Landing == As for jumping, angle is generally kept at 0 while you're in the air. And the speed when jumping is converted into x/y form instead of magnitude/direction (i.e. the way you're doing it). The formula to convert magnitude/direction to x/y including the jumping off of the slope you're on is: Vx = jump_power * cos(angle + PI/2) + speed * cos( angle); Vy = jump_power * -sin(angle + PI/2) + speed * -sin(angle); And to convert them back (i.e. when landing), it's (make sure you change angle to the slope of the curve you're landing on): speed = cos( arctan2( -Vy, Vx) - angle) * sqrt(Vx*Vx + Vy*Vy); 1 Link to comment Share on other sites More sharing options...
ClawHaMMer Posted September 7, 2008 Author Report Share Posted September 7, 2008 Thanks very much for the (super sonic) fast response Kain That sounds like just what I was looking for, hopefully I can make some more progression with this now Link to comment Share on other sites More sharing options...
Kain Posted September 8, 2008 Report Share Posted September 8, 2008 No problem. Here are some essential trigonometric functions which come up very frequently in working with game physics. And they're pretty much verbatim the solutions to these problems, so I thought they were worth mentioning: arctan2( -(y2-y1), x2-x1) - will give you the angle of the vector going from (x1,y1) to (x2,y2). sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2)) or sqrt(sqr(x1-x2) + sqr(y1-y2)) - will give you the distance from (x1,y1) to (x2,y2) cos( angle) * distance - will give you the x-component of a vector whose magnitude is distance and whose direction is angle -sin( angle) * distance - will give you the y-component of a vector whose magnitude is distance and whose direction is angle cos( angle2 - angle1) * distance2 - will give you the projection of This last one is used whenever your progress is impeded by an angle or something. This is the amount of your old vector gets transfered into your new speed. Link to comment Share on other sites More sharing options...
Rael0505 Posted September 8, 2008 Report Share Posted September 8, 2008 Welcome back, it's nice to see an old member return. Hope you stick around! Link to comment Share on other sites More sharing options...
ClawHaMMer Posted September 10, 2008 Author Report Share Posted September 10, 2008 Trig stuff Thanks again, I'm pretty decent with basic trig but those diagrams are a nice reference thanks Ive implemented slopes affecting speed now along with proper jumping, your post was very helpful thanks again Welcome back, it's nice to see an old member return. Hope you stick around! Thanks! I was never actually a member to the site but spent waay too much time fiddling with TGF and playing fangames, its interesting to see how far along things have come since then. Link to comment Share on other sites More sharing options...
Recommended Posts