May 23, 2012, 06:28:22 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Prowlie Welcome back! The site migration is complete and normal service resumed.
Advanced search
Pages: [1]   Go Down
Print
Author Topic: Something thats bugging me (AS3)  (Read 1625 times)
0 Members and 1 Guest are viewing this topic.
adzy-2k6
Senior Member
****
Offline Offline

Posts: 720


« on: May 22, 2009, 09:30:28 AM »

I began learning AS3 almost a month ago after fiddling about with a few other languages, and i think I have the basics down. I am able to make a simple platformer using tiles and flat surfaces, but now im hitting a snag. If i want to use a curved surface, i cant simply test where my character is in relation to the top of the MC, as the surface varies in hight throughout the MC now. The only way i can think of is using a hitTestPoint to see if the bottom of the character is overlapping with an active pixel on the floor mc, and move it up by a small amaount until it no longer overlaps, and using a hitTestPoint on other side of the first point to determine the angle. Is there a better way of doing this, such as calculating the position of the nearest blank pixel, or is moving the character up in steps the only way? In case you dont know what im talking about, imagine a curved skateboard ramp, and a character tries to run up it. I know how to test for the collision, but not how to actually handle it, and set the character back ontop of the ramp. Any help would be appreciated Smiley.
Logged

supermoose
Full Member
***
Offline Offline

Gender: Male
Posts: 240


Yes. I beat IWBTG. Only took ~60 hours of play.


« Reply #1 on: June 18, 2009, 02:30:48 AM »

Well, most curved surfaces have a distinct equation or formula behind them.  It my be a bit harder to find these in Flash, but its still possible.  If you make your ramp a quarter-circle, you can use the formula r^2 = x^2+y^2  Where r is the radius of the circle.  Using trig equations, you can also calculate the speed the character would need to go in each direction (x and y) in order to move along the curve.  If you would like me to get more specific I can, but that is how I would handle it.  I am currently working on a platformer myself, and I have an Xspeed and Yspeed variable I redefine as I move along surfaces.
Logged

adzy-2k6
Senior Member
****
Offline Offline

Posts: 720


« Reply #2 on: June 20, 2009, 08:54:52 PM »

I know what you mean, ive learnt all those equations from my maths course. i meant a curve as in a line hand drawn, and uneven. Looking at it, id need to use a series of hit-tests, one to define where the collision took place, and another at an angle to it to define the slope. Then, move the character accordingly. i was reluctant to do this, because im assuming that hit-tests use a lot of processing power...
« Last Edit: June 20, 2009, 10:32:45 PM by adzy-2k6 » Logged

Cel
Senior Member
****
Offline Offline

Gender: Male
Posts: 967


« Reply #3 on: June 20, 2009, 09:48:35 PM »

You can do it smarter. Split your game field into logic areas, and map their (x,y) ranges to corresponding collision groups. Then you just check the x,y position of the character, and cross reference with your mapping of areas. Then, instead of testing collision with everything and watching flash die, you'll just have hit tests with a few points.
Logged

My DeviantArt

<a href="http://img.photobucket.com/albums/v661/Vector88/sfx_3.swf" target="_blank">http://img.photobucket.com/albums/v661/Vector88/sfx_3.swf</a><a href="http://img.photobucket.com/albums/v697/Espengenin/banner1star-1.swf" target="_blank">http://img.photobucket.com/albums/v697/Espengenin/banner1star-1.swf</a>
supermoose
Full Member
***
Offline Offline

Gender: Male
Posts: 240


Yes. I beat IWBTG. Only took ~60 hours of play.


« Reply #4 on: June 25, 2009, 01:41:29 AM »

Ooh, that's a pretty good one Cel.  It would be a pain to create the table, but reading from a hash table at runtime would be waaay easier on a system than doing all those hit tests.  You could move the curve to a different movie for a bit to test all of it's x-y positions and the angle they give, and just make an array of all the values.
Logged

adzy-2k6
Senior Member
****
Offline Offline

Posts: 720


« Reply #5 on: June 25, 2009, 03:53:53 AM »

Cell, im not quite sure what you meant about the logic areas, but ive tried to put together a system myself. The game gets split into areas, and then using hit tests cna determine the gradients between defferent points, and using trig (this parts only at the characters locations whenever the code is ran, determine where the character is limited to, and at what angle it is moving. Not sure if this is quite what you meant, but i think i could come up with the coding to manage it Tongue.
Logged

Brackenwood
   

 Logged
Pages: [1]   Go Up
Print
Jump to:  

Theme by Pieter, based on Black Rain by Crip Powered by SMF 1.1.16 | SMF © 2011, Simple Machines XHTML | CSS

Page created in 1.572 seconds with 25 queries.