HOME | DD

Published: 2005-02-14 01:08:06 +0000 UTC; Views: 3246; Favourites: 24; Downloads: 1485
Redirect to original
Description
Flash 'R' Us TutorialCollision tutorial
Author:
Skill level: 3
Teaches:Collision detection, uses for it
Orginal Source of tut
[link]
(If you like this tut and want to fav it, pls fav at this link)
Related content
Comments: 16
little-teenager-sam [2006-08-23 11:34:51 +0000 UTC]
i've got a problem. i made my object before doing this tut and i wrote some script that tells it to move on keypress. now i only added the part of your code (if (this.hitTest(_root.hitbox)) {
}
}
)
it isnt working!! what is wrong??
anyway great tut, i've been lookin for this for a long time.
👍: 0 ⏩: 1
little-teenager-sam In reply to little-teenager-sam [2006-08-23 12:00:51 +0000 UTC]
here's the code i used:
onClipEvent (load) {
_quality = "high";
moveSpeed = 10;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT, true)) {
this._x += moveSpeed;
_root.dude.gotoAndStop(2);
} else if (Key.isDown(Key.UP, true)) {
this._y -= moveSpeed;
_root.dude.gotoAndStop(4);
} else if (Key.isDown(Key.DOWN, true)) {
this._y += moveSpeed;
_root.dude.gotoAndStop(5);
} else if (Key.isDown(Key.LEFT, true)) {
this._x -= moveSpeed;
_root.dude.gotoAndStop(3);
} else {
_root.dude.gotoAndStop(1);
}}
if (this.hitTest(_root.hitbox)) {onClipEvent {setProperty(_root.this._x += movespeed=0;
}
}
}
what's wrong? (i wanted my object to hit the hitbox so it couldnt pass it)
👍: 0 ⏩: 1
Rowing1s4me In reply to little-teenager-sam [2007-04-26 04:12:11 +0000 UTC]
first off, i get these errors when i try your code:
**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 21: '(' expected
if (this.hitTest(_root.hitbox)) {onClipEvent {setProperty(_root.this._x += movespeed=0;
**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 23: Unexpected '}' encountered
}
Total ActionScript Errors: 2 Reported Errors: 2
~~~
Lets try a simple approach.
Lets assume you are running to the right into a wall for this one...
if (this.hitTest(_root.rightHitWall)) {
//make sure you "rightHitWall" is labeled "rightHitBox"
_root.this._x -= moveSpeed;
//this should move you out of the rightHitWall the instant you move into it...
//you wont even see it, like not moving, but not imparing your movement
}
Sooo, now you want the dude to be able to move up against the wall without touching it, and when he moves more he will be in the wall, but forced back out before you see anything. So you will test it and move the wall or the dude so when you play, the can ALMOST touch each other.
This code can be duplicated and modified for the dude colliding into a different wall a different way.
👍: 0 ⏩: 0
Sayumichan [2006-04-27 13:38:36 +0000 UTC]
err, I don't quite understand it, but I'll keep trying^^"
👍: 0 ⏩: 0
thecarrot [2005-03-16 13:10:15 +0000 UTC]
Thankyou!!!!!
I have been searching for how to do that in a way that I of little intelect can understand, and this is it!
Thankyou!!!!!!
👍: 0 ⏩: 0
zaceryspud02 [2005-02-14 07:14:03 +0000 UTC]
Okay I knew that but I want to know if there is a way to create a collision test for a round object. You see the main problem I find with this is that the collision tests the bounds of the movie objects and therefore tests the bounding box of the movie rather then the actual object. The corners of a ball will still set of the hitTest intersection even though it doesn't actually touch the ball.
I want this for landscape movement and more accuracy or else my objects may have to be broken up into sprites sections for the meantime. Ie a movie for the arm and a movie for a leg instead of just the whole person.
If I find out how to create a more accurate way of testing intersections I will tell you... and perhaps make a tutorial as well to help other people. I'm sure it would help alot.
👍: 0 ⏩: 1
SoxyFoxer In reply to zaceryspud02 [2005-02-14 21:55:19 +0000 UTC]
there is a simple way to do it I just forgot how, basically theres an option to not use bounding boxes and go by the actual vector. If I get around to remembering it i'll post it up.
👍: 0 ⏩: 1
zaceryspud02 In reply to SoxyFoxer [2005-02-15 07:28:15 +0000 UTC]
Oh that would help me so much you wouldn't believe it. Please do ^^
*sits down eagerly and grabs an etchosketch(sp?)*
👍: 0 ⏩: 0
SoxyFoxer [2005-02-14 05:53:05 +0000 UTC]
Now all I need to know is how NCH uploaded such a clean preview image, because the one on my page looks messy at the top.
👍: 0 ⏩: 0
wingedcentaur [2005-02-14 02:02:14 +0000 UTC]
OMG! I put the jig saw puzzle together! w00t! That's awesome!
Eventualyl I will download flash and try this...eventually.
👍: 0 ⏩: 0