# Physics and collisions

**URL:** <https://forum.kirupa.com/t/physics-and-collisions/9011>\
**Category:** Uncategorized\
**Created:** [December 3, 2002, 1:38am UTC](https://forum.kirupa.com/t/physics-and-collisions/9011 "2002-12-03T01:38:37Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![RealTK](https://avatars.discourse-cdn.com/v4/letter/r/9dc877/32.png) [@RealTK](https://forum.kirupa.com/u/RealTK)\
**Post date:** [December 3, 2002, 1:38am UTC](https://forum.kirupa.com/t/physics-and-collisions/9011/1 "2002-12-03T01:38:37Z")

</div>

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. 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 3, 2002, 2:46am UTC](https://forum.kirupa.com/t/physics-and-collisions/9011/2 "2002-12-03T02:46:16Z")

</div>

Thats something I would like to know…lol.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 3, 2002, 3:15am UTC](https://forum.kirupa.com/t/physics-and-collisions/9011/3 "2002-12-03T03:15:50Z")

</div>

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](http://www.bit-101.com), 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:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 3, 2002, 3:32am UTC](https://forum.kirupa.com/t/physics-and-collisions/9011/4 "2002-12-03T03:32:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 3, 2002, 11:15am UTC](https://forum.kirupa.com/t/physics-and-collisions/9011/5 "2002-12-03T11:15:36Z")

</div>

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. 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 3, 2002, 11:40am UTC](https://forum.kirupa.com/t/physics-and-collisions/9011/6 "2002-12-03T11:40:22Z")

</div>

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.)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 3, 2002, 11:57am UTC](https://forum.kirupa.com/t/physics-and-collisions/9011/7 "2002-12-03T11:57:28Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 3, 2002, 1:43pm UTC](https://forum.kirupa.com/t/physics-and-collisions/9011/8 "2002-12-03T13:43:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 4, 2002, 11:57am UTC](https://forum.kirupa.com/t/physics-and-collisions/9011/9 "2002-12-04T11:57:12Z")

</div>

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. 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 7, 2002, 11:49pm UTC](https://forum.kirupa.com/t/physics-and-collisions/9011/10 "2002-12-07T23:49:54Z")

</div>

Anyone know a way to use hitTest with a MC without the  
object “falling through” the MC? 😏

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 8, 2002, 1:10pm UTC](https://forum.kirupa.com/t/physics-and-collisions/9011/11 "2002-12-08T13:10:09Z")

</div>

> \*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](http://www.bit-101.com), 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: \*\*

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 8, 2002, 4:59pm UTC](https://forum.kirupa.com/t/physics-and-collisions/9011/12 "2002-12-08T16:59:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 8, 2002, 11:09pm UTC](https://forum.kirupa.com/t/physics-and-collisions/9011/13 "2002-12-08T23:09:07Z")

</div>

If **anyone** can help me figure this out, please reply…  
I need to get this working with many platforms… Here’s the fla. :cyclops:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 9, 2002, 9:23pm UTC](https://forum.kirupa.com/t/physics-and-collisions/9011/14 "2002-12-09T21:23:42Z")

</div>

: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 \<:}

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 9, 2002, 11:15pm UTC](https://forum.kirupa.com/t/physics-and-collisions/9011/15 "2002-12-09T23:15:33Z")

</div>

Heh, ok… Thanks for the help in advance. =)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 10, 2002, 2:28am UTC](https://forum.kirupa.com/t/physics-and-collisions/9011/16 "2002-12-10T02:28:07Z")

</div>

: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 \<:}

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 10, 2002, 6:50pm UTC](https://forum.kirupa.com/t/physics-and-collisions/9011/17 "2002-12-10T18:50:11Z")

</div>

I didn’t know anything about a pixel displacement speed setting…  
How can I set it?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 10, 2002, 10:01pm UTC](https://forum.kirupa.com/t/physics-and-collisions/9011/18 "2002-12-10T22:01:17Z")

</div>

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 \<:}

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 11, 2002, 8:51am UTC](https://forum.kirupa.com/t/physics-and-collisions/9011/19 "2002-12-11T08:51:21Z")

</div>

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?
