PDA

View Full Version : Collision?


rustyofco
04-29-2005, 10:33 PM
How do you say , "If (object1 hits/touches/collides with object2) {destroy both of them and creat object3 in their place}"

AND also, how can you move an onbject? Like, "if (so and so happens){have object4 move in this direction at this speed}"

Ricod
04-30-2005, 12:50 AM
We have a tutorial written by Billy T, which covers the basics for making a game in Flash, including moving objects and collision detection : http://www.actionscript.org/tutorials/beginner/games_in_flash/index.shtml

When you get stuck, let us know !

rustyofco
05-02-2005, 05:31 PM
i have,
if (object1.hitTest(object2._x, object2._y)) {then something happens}

but it doesnt work!!1

Ricod
05-03-2005, 02:57 PM
There are several possibilities (urgh, that spelling of mine ... :rolleyes: )

- the paths are wrong. Use absolute paths to be absolutely (sorry, bad word joke) sure ! Also make sure the mcs are labeled (the instances) 'object1' and 'object2'

- The code for what to do when a collision occurs is faulty. There can be typo's or wrong paths here as well.

We can't see that from over here, so you'll have to check for that yourself first. Of course, there are other things that could have gone wrong, but I can't think of any right now.

But my next advice would be : "It doesn't work" isn't a helpful post. We don't know what to do with that. We need to do what it does do and what it's supposed to do. We already assume it's not doing what you want, because otherwise you wouldn't be here. ;)

rustyofco
05-03-2005, 05:12 PM
OK, the thing still dont work. I used absolute paths now. This is the exact text from my actionscript so check for mistakes here...

onClipEvent (enterFrame) {
if (this.hitTest(_root.bearcar1._x, _root.bearcar1._y)) {
gotoAndPlay(50)}
}
In this AS, "this" is object1 and "bearcar1" (dont ask) is object2. Both are placed on the root stage. BTW, this might be key; both of these objects are moving. Their position is constantly changing, that is why i put the onEnterFrame.

Also, does this code mean that these two objects must meet at the one exact pixel? Or can they touch each other from anywhere?

Another thing, I'm using MX2004 if that affects things...

lilkinoko
05-03-2005, 06:48 PM
if (object2.hitTest(object1)){
destroy object 1 and 2... make 3
}

to make object 4 move, say whenever you press up?

mySpeed = some number;
if(Key.isDown(Key.UP)){
object4._y -= mySpeed;
}

lilkinoko
05-03-2005, 06:50 PM
if you go
if (object1.hitTest(object2._x, object2._y))
then it test one object and one pixel

but if you go
if(object1.hitTest(object2))
then it's wherever it touches

rustyofco
05-04-2005, 03:21 AM
The code still deosn't work!

This is angering me.... Here is the .fla file i made in 2 minutes to try out the AS... It is zipped.

http://www.geocities.com/vgr115/test1.zip

Fix that for me, thanks

Ricod
05-04-2005, 08:20 PM
Ehrm, the hitTest works fine in your example. Replace 'stop();' with 'trace("it hit");' for instance, and you'll see it traces it fine. If you wanted the animation to stop, then you should've used '_root.stop();'

I normally don't respond well to 'fix this' by the way. I tend to ignore future posts when I see that. I suggest you don't ask in such a demanding manner in the future. It helps getting answers from people, since I'm not the only one who thinks like that.