Next I’m going to make a game with ball physics on it so if anyone can tell me how to make ball physics with bouncing from angled objects, I’d be really grateful. =)
Also, I need the collision detection to be based on movieclips because
I need to be able to modify the levels in the game.
Thats something I would like to know…lol.
If you’re serious about games (and even if you’re not) I strongly recommend you to buy Jobe Makar’s Flash MX Game Design Demystified. He explains everything very clearly, from very simple trigo stuff to collision detection and collision reaction. There are many case studies too.
If you’re broke, well, you can visit bit, he has some of the best flas about collision detection. The problem is that you’ll have to look for them (but it’s worth the time, don’t worry).
pom :cowboy:
So many books to get…lol.
Yeah, bit has some good stuff, but if you don’t know any AS you should learn some before you attempt to figure out what bits code does. Although his code is nicely written and not too hard to understand, it will be if you don’t know AS.
Actually I saw a post here earlier that had a link to bit-101.
I went there and I was astonished by his creations. :o
Actually, I was thinking that asking someone here would make understanding things easier.
Still… If anyone knows how to make collision detection on movieclips NOT using hitTest, please let me know… Any way of calculating an angle if the movieclip isn’t in an angle
but its contents are, please let me know that too.
Thanks.
If you’re not using hitTest then you’ll have to map out target areas and determine if the MC is within the boundary specified by referencing _x and _y.
It tends to be far simplet to place each MC into an array and use a for loop to iterate through the hitTests. Just remember to remove each MC when it is no longer on screen - e.g. bullets that have been fired off screen - otherwise you’ll be performing a lot of redundant hitTests.
As regards simple physics: if you start by changing the rate of change of _x and _y you can emalutate all trig functions -
Assume you nest this is an onClipEvent(enterFrame) handler
_x+=0 _y-=1 will give 0 degrees or North
_x+=1 _y-=1 will give 45 degrees or North East
_x+=1 _y+=0 will give 90 degrees or East
_x+=1 _y+=1 will give 135 degrees or South East
_x+=0 _y-=1 will give 180 degrees or South
and so on …
(you don’t of course need to put in the redundant code x+=0, etc.)
Maybe I could use hittest with all the levels platform MCs in one MC.
It’s just that hitTest is too slow(?) and the ball tends to fall through platforms or remain inside them. :-
And how could I calculate angles when the MCs are in one MC?
I mean, how to determine which MC inside the MC the ball hits?
That doesn’t matter though… I just want to get the collisions
working so that the ball wouldn’t fall through the platforms… :-
Oh, and there’s more… If I got the collisions working, how would I make them to work sideways also (like in platformers because this is gonna be one )
meaning that if the ball hits a platforms left side, it should bounce left, not up…
you can nest your hitTest - e.g.
while (this.hitTest("_root.targetA")){
if (this.hitTest("_root.targetA.targetA01")){
}
}
or loop through an array.
I’ve never found speed to be too much of a problem with arrays providing you remove redundant elements from an array. you could condiser using a for () in () loop to declare an array of the elements within the level MC which could theoretically collide.
As regards rotation - you’re probably found the _rotation property - this give the value of the nested MC relative to the parent e.g. if
MC_A contains MC_A_01
if the rotation of MC_A is +15 and the rotation of MC_A_01 is +45
then the apparent rotation will be +60 although _rotation will return +45.
You can correct this with a
while (_parent.name!=_root.name){} loop
Sorry for being idle there for a while but I was working on the other games
highscore list and playing some games.
Thanks for the help jsk, I’ll try it out.
Anyone know a way to use hitTest with a MC without the
object “falling through” the MC?
*Originally posted by ilyaslamasse *
**If you’re serious about games (and even if you’re not) I strongly recommend you to buy Jobe Makar’s Flash MX Game Design Demystified. He explains everything very clearly, from very simple trigo stuff to collision detection and collision reaction. There are many case studies too.
If you’re broke, well, you can visit bit, he has some of the best flas about collision detection. The problem is that you’ll have to look for them (but it’s worth the time, don’t worry).
pom **
Well… I could try the book but I really like people more than books you know… =)
And BIT-101… Well, I have a little trouble figuring out the sources from BIT-101 and second… I haven’t found ANY coding there that uses hitTest with objects.
If anyone can help me figure this out, please reply…
I need to get this working with many platforms… Here’s the fla. :cyclops:
:ninja: Hey there…
I can help you out with your problem… Wlel not by looking at the .fa cause it must be for MX and I have Flash 5… lol… But… I made a small paddleball game that uses hittests and stuff ike that… Will comment further on ideas you should use then…
For right now though… The pottie fairy is visiting and I need to go smack her around lol
Peace
Marz <:}
Heh, ok… Thanks for the help in advance. =)
:pirate: Allright let’s see here… Try this out:
I don’t know what pixel displacement speed you have for the settings but you might want to set them a little lower…
But then your ball will be slower correct? To correct this problem just make your fps alot faster. I figue… Going 3 pixels at 40 fps would let your ball travel 120 pixels from it’s current position every second… That should be enough speed and it should allow your ball sufficient space to test whether it hits the paddle or not.
Umm… Just a hint… Figured this would help a little. f you could take a screenshot of some sort and show me what you are tlaking about… I could examine it closer… Or if I just got off my lazy butt and actually got MX instead of 5… lol
Peace Out,
Marz <:}
I didn’t know anything about a pixel displacement speed setting…
How can I set it?
No… What I meant by pixel displacement speed is this…
x += 5;
Saying you will move the object 5 pixels int he x direction…
Soemtimes if you set that number too high… The object that is moving can jump over the object you are trying to hit… Therefore not actually colliding…
Peace Out,
Marz <:}
Ahh, that’s what you meant… Well that’s low.
Anyways… I don’t need help with that anymore, I got it working! =)
Still I have one question (anyone? :-\ ) how do I use shape flags to determine collision to the shape (not the box)???
Add: I just saw something on a thread…
That you can’t use shapeflags if two movieclips are colliding together.
Is there any way to go around this?