ForumsProgramming ForumI need help with as3

3 5196
HoundByte
offline
HoundByte
1 posts
Nomad

i tried to make sure that when my circle hits the blue platforms(which are in the floors array) that it would stop its gravity
but the character stops his gravity in mid air reguardless like if i was testing the whole level.

for (var i:Number = 0; i < Main.floors.length; i++)
{
if (Main.floors[i].hitTestObject(this))
{
grav = 0;
jumped = false
}
else
{
grav++;
}
}
but im not..im testing the blue platforms in my testlevel...or do i hitTest against the whole class itself?

link//www.mediafire.com/?g7916hzac0xyzit

  • 3 Replies
PixelSmash
offline
PixelSmash
566 posts
Nomad

First guess is that is has to do something with your hittestobject... That function compares the two bounding boxes, not the actual shapes.

I assume 'this' is the character - in which case you'd probably be better off with the hittestpoint function, since that allows for a shapeflag (so it doesn't just test against the bounding box). You'd have to define a point at the bottom of the character's feet though.

jasonjie88
offline
jasonjie88
28 posts
Nomad

I assume 'this' is the character - in which case you'd probably be better off with the hittestpoint function, since that allows for a shapeflag (so it doesn't just test against the bounding box). You'd have to define a point at the bottom of the character's feet though.


What are you DOING?! D:

Tip number one: Use an AABB sweep test for the character. That's going to max out your hit-testing accuracy, because you're checking the lines the square will be moving through, not the actual object. Otherwise, tunneling occurs.

Tip number two: DON'T use hitTestPoint! Ever! In fact, don't use any sort of hittesting the Flash IDE offers you! It is NOT going to give you the best results. Have you heard of Seperating Axis Theorem? Believe it or not, that is faster than hitTestObject.

Tip number three: Never, EVER loop through objects. Sure, it's easier to implement a loop, but it's not good in the long run. If you want your game to run as fast as possible, you need to cut down on the amount of loops you do. That is rule number one for optimization: If you don't need to do the test, don't do it.

Tip number four: Don't use movieclips. Use bitmaps. And if the blocks are animated, use blitting. This will drastically improve performance.

Platform games can be so hard to program, and a lot of people can make mistakes. Here the mistake is that you are checking if the character is hitting anything at a particular time. You're not checking for what he hits along the way. That's called real-time collision detection, and that's why AABB sweep tests are really good to use here. This link may be able to help you.
PixelSmash
offline
PixelSmash
566 posts
Nomad

In short: yes, you're right, but baby steps...

Nice link though, I hadn't seen that even though I occasionally check Kong - definately warrants a longer read!

Showing 1-3 of 3