Collision Detection Within A Rotating Movieclip
I am working on a snowboarding game, And have two points of collision detection on the board: x-----xOne at the Front of the riders boardOne at the Back of the riders boardThese two points of collision are placed within the rider.movieClip, and not on the _root timeline, as the rider movieclip can rotate etc as it rides through different gradients of slopes. I have used a largely basic method to obtain the X,Y positions of each collision point, using the following method: Code: var backX:Number = _root.rider._x+_root.rider.backDetection._x;var backY:Number = _root.rider._y+_root.rider.backDetection._y; (the same for the frontX and frontY) As you can see, it simply adds the offset of the detection points positions from the riders x, y therefore when the rider movieclip is rotated during gameplay, the rotation is not accounted for and it still searches for collision in exactly the same positions.I am using this for collision checking: Code: this.hitTest(backX, backY, true) which is placed on the ground movieclip (what the snowboarder is riding on)Can anyone suggest a better way of doing such collision checking, or how to account for rotation? is localToGlobal() the answer?Cheers for any help.
KirupaForum > Flash > ActionScript 1.0/2.0
Posted on: 02-15-2007, 03:51 AM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Collision Detection Between A Circle And A Rotating Line
What's the best way to catch a collision between a small circle and a rotating line in AS3?
These are my attempts:
1) line.hitTestObject(circle)
Result: This is really not good. The circle goes in collision with the bounding box of the line.
2) line.hitTestPoint(circle.x, circle.y, false)
Result: With "false" we have again the bounding box. So let's try with:
3) line.hitTestPoint(circle.x, circle.y, true)
Result: it's a little better now but the detection is still imprecise. There's always a small bounding box
and the function is sometimes true even if the objects are not touching each other.
4) I tried with the AS3 version of the Skinner's collision detection class but I can't get it working in
any way. It's based on collision rectangles and for some reason the collision is never detected, as if the
objects don't exist. I can't tell you now all the attempts I tried to get it work but I've tried
everything, I think..
So, have you any other kind of solution to get a working collision detection between these 2 shapes??
Thank you!
Advance Collision Detection For A Rotating Object - I Need Some Real Help
http://www.gamingforever.com
The second one on the list is "Simple Fun". I got it working pretty good, but the objects flying around trying to hit you are kind of buggy. You can be ALMOST touching them and they will hit you. I was wondering if anybody had a solution to the problem. Maybe some kind of link to a tutorial?
Thanks,
Scott
(If you would like to just code it, I'll send you a Flash MX or MX 2004 FLA. BEWARE: I use flash 4 syntax.)
Movieclip Collision Detection
Im making a pretty basic game, (which I;ve never done before), so I dunno if this is a really noobly question, but here goes....
What I want is when a two movieclips collide, one of them switches to a different movieclip.
Or another way to put it is, I want things to die when i shoot 'em.
EDIT
Umm, ok, I got a new idea, I could have it to goto the next frame inside of changing movieclip when the movieclips collide, that should be much simpler. I do however still need to know how to make it detect the collision, that's all I need.
MovieClip Collision Detection Question
Here is the simple version of the code. BOX and Coin1 are MovieClip's on the stage.
ActionScript Code:
stage.addEventListener(Event.ENTER_FRAME, enterFrame);
BOX.addEventListener(MouseEvent.MOUSE_DOWN, boxStart)
BOX.addEventListener(MouseEvent.MOUSE_UP, boxStop)
function enterFrame(e:Event):void {
if(BOX.hitTestObject(Coin1)) {
removeChild(Coin1);
}
}
function boxStart(e:MouseEvent):void {
BOX.startDrag();
}
function boxStop(e:MouseEvent):void {
BOX.stopDrag();
}
I made a simple little game that technically works fine, but the output log window is streaming this error
ActionScript Code:
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display::DisplayObjectContainer/removeChild()
at BoxandBalls_fla::MainTimeline/enterFrame()
There is a box movieclip that you can drag around with your mouse. There are some coins (also movieclips) that you collect, then go to the finish area.
When the box moves over the coins, it works fine, but as long as you hold the box over the space where the coin used to be, it streams that error.
Technically the game works great, I'm just worried about that error. Anyone know why it's coming up, and what I can do to make the game run more "cleanly"?
Thanks,
Colin
Moving Movieclip And Collision Detection
Ok now let me say I'm farthest from a good programmer, but I've been teaching myself Flash MX from the ground up but I've come upon a slight hitch.
I'm creating a basic shooter, ship centered, rotates to mouse angle etc etc. I'm trying a few easy games before I start creating what I want to really create, but I digress.
The problem I'm having is this. In the clip, there is 2 frames. The first frame does something like this (not at home or I'd just paste the code):
Code:
onMouseDown
X++
duplicateMovieClip("bullet_new","bullet_new" add x, x)
In the first fram that part works fine, it creates a new bullet clip and increments the name 1 every time so it doesn't create similarily named instances. Anyhow, the problem I'm having is this. I pasted some action script from a tutorial to learn from and rewrite as my own, but the way their tutorial works, the bullet slows down as it approaches the mouse click x and y. When it reaches where the mouse was clicked it stops! What I preferred was to just have the bullet continue until it left the screen, and then remove itself once off the screen to keep the load light on the pc so the game runs smoother. I was making progress using Math.atan, but I haven't been able to figure out how to increment the bullet_newx's x and y value to have it just continue in that angle, and delete itself once off screen.
Oh and the code to do this is in the second frame, but I've noticed with the tutorial code that I pasted, I needed to have a copy of the original bullet_new in BOTH frames with the actionscript inside of each one so that it keeps updating. Sorry, I'm really new to this but I really want to learn it. Thanks for your time.
Any suggestions are welcome and appreciated.
Marc
AS3 - Rotating Collision - Please?
Here's a somewhat finished .swf that I made -
http://www.mediafire.com/download.php?cmhzlmowiji
If you look at it, you can see what's wrong. The circle is supposed to stop at the ends of the stage, meanwhile it hits the edge, bounces back a bit, and repeats the action. Here's the source code:
Code:
var pressedKeys:Object = {};
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyHandler);
stage.addEventListener(KeyboardEvent.KEY_UP, keyHandler);
stage.addEventListener(Event.ENTER_FRAME, moveCharacters);
function keyHandler(e:KeyboardEvent):void{
if(e.type == KeyboardEvent.KEY_DOWN){
pressedKeys[e.keyCode] = 1;
}
else{
delete pressedKeys[e.keyCode];
}
}
function moveCharacters(e:Event):void{
var x:Number = 0;
var y:Number = 0;
if(pressedKeys[Keyboard.RIGHT]){
wheel.rotation += 10;
wheel.x += 3;
}
if(pressedKeys[Keyboard.LEFT]){
wheel.rotation -= 10;
wheel.x -= 3;
}
if(wheel.y >= stage.stageHeight - wheel.height/2){
wheel.y = stage.stageHeight - wheel.height/2;
}
if(wheel.y <= 0 + wheel.height/2){
wheel.y = 0 + wheel.height/2;
}
if(wheel.x >= stage.stageWidth - wheel.width/2){
wheel.x = stage.stageWidth - wheel.width/2;
}
if(wheel.x <= 0 + wheel.width/2){
wheel.x = 0 + wheel.width/2;
}
}
How can I fix this problem? When I got rid of the parts of the code that rotate the circle, it works just fine. So is there something that I'm missing?
Thanks in advance =D
Collision Detection
I have many instances of a movie clip (by using duplicateMovieClip) on my stage, each with a name of "clip1", "clip2", "clip3" etc.
I have many instances of another movie clip, like the one above, but all derived from a different original movie clip. They're named "something1", "something2" etc.
I want to put an "if" statement that performs a "hitTest" between one of the "something" movie clip instances and ANY of the "clip" instances.
This is the code I have inside the onClipEvent (enterFrame) of the "something" instance:
onClipEvent (enterFrame) {
if (this, hitTest(_root.varClip)) {
this.removeMovieClip();
}
}
and I have this code in a frame on the _root level
for (var i = 1; i<=3; i++) {
_root.varClip = ["clip"+i];
}
Nothing is working this way. Is there some other way that I can check the collision using arrays?
Am I mixing up the paths?
I'd really appreciat some help with this. I feel like I'm so close already.
Thanks
Kevin
Collision Detection
Alright troops?
I wonder if any kind (and talented) souls could give me a hand? I'm trying to build a pac-man type maze game and I'm not sure about how to produce collision detection to stop my character goin' through the walls. I'm really not sure where best to begin on this one, so any advice at all is greatly appreciated.
Cheers
Collision Detection On 5
I'm using the collision detection feature on Flash 5, which works nicely, but I don't know how to make a movie detect another instance of itself without detecting itself
To illustrate what I mean, I'm making a battle of Ants. Each ant is created by an Array, and I want their heads to detect the collision with another. So I'm using the following code within the 'head' movie:
flag = this.hitTest(_root.ant);
if (flag == true) { do something... }
What should I use instead of _root.ant?
Thanks!
Collision Detection
Hi,
I am trying to make a game. I have a character and a 3d floorplan he walks around in. Instead of moving the guy, I move the floor so it looks like he is moving, but he stays in the center of the screen. So I got the hit test to work, but I have one big object that my character is colliding with (the map). I know that I can break apart the floor and have separate walls, but I was hoping there is a way to keep using only one object. The object is vector, so why can't flash only see the filled in areas? If anyone can help me with this, I would greatly appreciate it. Thanks.
Stan
Collision Detection
hey guys
i'm trying to create a game where you're a tank and you move around using the mouse (you click where you want to move to and the tank drives in a straight direction towards the mouse)
I know how to make the tank move, the thing i need help on is the collision detection, the tank is a rectangle movie clip and the object i am colliding with is a rectangle too.
this is what i need to happen:
when the tank collides with the object, the tank will stop
there's a varable in the tank MC that if it is set to TRUE the tank will move, if FALSE the tank will stop where it is
the variablie is called 'GO'
i know the basic
if(this.hitTest(_root.object)){
this.go = false;
}
but if i do this, then the tank will still be touching the object, so when the tank touches the object, i would like the tank to be moved 5 pixels away from it so it wouldn't be touching the object
is there anyway i can do this?
Collision Detection
Ok, um i have this video clip that i can move around the screen using the arrow keys on the keyboard. I also have some other graphics on the stage. Now, what i want to do is when the movie clip touches one of these other graphics the movie clip stops and it cant go over the particualr graphic. so i now hae to move the mvie clip around the graphic. Can someone please help me on how to do this. Your help is greatly appreciated. Thank you in adavance for any help you can offer.
Kind Regards,
The Prophecy.
Collision Detection
i want to have a mc follow the cursor and when it collides with another mc an action is done.
Collision Detection
Here's what I'm trying to do:
Go to and play frame 5 when MC1 AND MC2 have both been dragged into a certain area.
I got both MC's to be draggable into a red box but how do I check to see if both are there and if so move on and if not wait until they are?
Thanks
Collision Detection
hello,
i have a MC which carries the follwoing script. when the MC detects collision, corresponding MC instance will start.
onClipEvent (enterFrame) {
this._y+=laserSpeed;
if (this._y<-50) {
this.removeMovieClip();
}
if (this.hitTest(_root.map.ground.target_pro)) {
_root.pro.gotoandstop(2);
this.removeMovieClip();
}
if (this.hitTest(_root.map.ground.target_edu)) {
_root.edu.gotoandstop(2);
this.removeMovieClip();
}
if (this.hitTest(_root.map.ground.target_work)) {
_root.work.gotoandstop(2);
this.removeMovieClip();
}
if (this.hitTest(_root.map.ground.target_ex)) {
_root.ex.gotoandstop(2);
this.removeMovieClip();
}
if (this.hitTest(_root.map.ground.target_ski)) {
_root.ski.gotoandstop(2);
this.removeMovieClip();
}
}
Q1 does anyone know why only four out of five collision detection work? the MC "pro" does not detect collision...i ckecked instance names etc but just don't have a clue why it doesn't work!!
Q2 does anyone know how to create a master script so that i don't have to repeat the same if(this.hitTest...) script? how can "this" (the main MC that holds the script above) find out collided object's instance name??
any help greatly appreciated!
Thanks!
reynard
Collision Detection
does anyone know the ode for collision detection and how to make a rotating objet move in the direction it's pointing?
example :
I I
I I I = wall
I I <O> = object
I I
IIIIIIIIIIII IIIIIIIIIIIII
<O>
IIIIIIIIIIII IIIIIIIIIIIII
I I
I I
I I
I I
i want the user to be able to press UP to go forwards and DOWN to go backwards. He can the press RIGHT / LEFT to choose the direction he will move in...
plz help
Collision Detection
Ok, I'm making a pong game, but the collision detection system I'm using doesn't work too well. The ball will be inside the paddle before it reverses direction and sometimes it just goes straight through. I know there's a better way than just using hitTest(even with the borders on). Anyone have ideas?
Collision Detection Help
Hey--
I'm having a problem with my collision detection. I followed a tutorial and downloaded the fla to double check, but its not working. I have one mc called laser, which's actionscript is "
onClipEvent (load) {
laserMoveSpeed=20;
this._x=_root.spaceship._x+90;
this._y=_root.spaceship._y;
}
onClipEvent (enterFrame) {
if (this._name<>"laser"){
this._x+=laserMoveSpeed;
if (this._x>600){
this.removeMovieClip();
}
for (i=1; i<=_root.numEnemy; i++){
if (this.hitTest( _root["enemy"+i])){
_root.score+=100;
_root["enemy"+i].gotoAndPlay( 2 );
}
}
}
}
"
And the enemy it's killing's movie clip is called enemy one, and its action script is"
onClipEvent (load) {
function reset(){
this._x=600;
this._y=random(200)+100;
enemySpeed=random(4)+1;
this.gotoAndStop(1);
}
reset();
}
onClipEvent (enterFrame) {
if (_root.spaceship.scrollStart){
this._x-=enemySpeed+_root.mainGround.groundSpeed;
} else {
this._x-=enemySpeed;
}
if (this._x<-10) {
reset();
}
if (this.hitTest( _root.spaceship ) ){
_root.gotoAndStop ( "gameOver" );
}
}
"
any help appriciated.
Thanks
Collision And Detection
Can anyone help me?.. I need to know how to simulate molecules leaving a surface within a chamber. The simulation
should behave as real as possible wherein if a molecule hit
the wall of the chamber, it should deflect at the same amgle
Collision Detection
hi all
1. i have drawed some lines with actionscript
2. i have let's say a circle which i move around
now i need to make a collision detection so when the circle does collide with one of the lines it has to stop.
can someone tell me how i can do that.
thx a lot in advance
marcel
Collision Detection
am trying to create game where someone throws ball to hit target. the target is moving. the ball is necessarily embedded in another movie clip. how do i get the x y coordinates to consider the same registration basis. meaning, x for one is not x for the other so i cant have "if ball.x = target.x then"
Collision Detection
Hi,
Is it possible to do pixel perfect collision detection with a clip on a clip in Flash 5? I know its possible using the mouse x,y but need to know if theres a way of doing it between 2 clips.
thanks
phil.
Collision Detection
Could someone please take a quick look at this Fla I have 2 mcs that u control via the keyboard one is with the arrow keys and the other is with W A S D keys.
I have another two movieclips that are a sort of barrier to the others when the green square hits the big blue square u r stuck the same with the other one but this is not the problem.
The problem is that the two keyboard controlled movie clips overlap. Is there a way to when they collide they hold there position on the stage but u are still able to maneuver them just not in the direction of the other MC.
Thanks
Collision Detection.. Help
Hi ya
Im making a fighting game and Im stuck on the actionscripting...
I have a 'health bar' for each player and when player 1 hits player 2 I want player 1s health bar to go up a notch, etc. Ive created the movie clips for each health bar but dont know what action scripting to put in to make it all come together....
Its driving me mad!!!
(Theres only 3 moves for each player and they're all seperate movie clips, incase you were wondering)
Please somebody help!
thankyou
lou
Collision Detection
What is the best way to detect collisions between multiple objects of certain types, for example, any of a "laser beam" movie clip hitting any "bad guy" movie clip on the stage at any time, like in a spaced invaders game? I tried looping through all the laser mc's on the stage and seeing if they hit any of the bad guy clips, but i think it is bogging down the proc so much that it misses most of the hits...
Dave
Collision Detection
What is the best way to do collision detection for a flash game with a bunch of different "bad guy" objects, and "laser gun" objects, or something like that?
Dave
Collision Detection?
Hi!
I'm making this webpage where you drive a car around with the keyboard. When the car drives over certain objects, I want them to light up, and if you press e.g. enter when over one of them, a movie should open.
I have read all kinds of different tutorials about collision detection to try to pick something up there, but I just can't make it work...
Would really appreciate it if someone would be willing to help me out on this one!!
Tnx, Thomas.
Mc Collision Detection
I've followed the basic tutorial on mc collision detection and attempted to ammend it slightly for my needs.... it didn't work.
I've attached the fla file as it's the best way to show what I'm attempting to do:
basically, I need a gotoAndPlay action to occur when 2 mc's collide - the two clips are currenty one stationary and one a drag mc. when one is dragged over the other I need the 3rd mc 'jwooClip' to go to and play frame 2.
I've used the correct actionscript for this part but not sure if it's tied in correctly with the rest of the script????
I know this makes little sense but it will all be clear if you view the fla file.
Any help will be appreciated, even if it's a link to another tutorial (intermediate maybe??)
Collision Detection
Is it possible to use collision detection to make objects bounce off one another?
Help Please (Collision Detection)
I'm working on a very basic RPG engine, and I'm trying to work on collision detection (if you run into an enemy on the map, you go to a battle screen).
I've tried several collision detection methods from several tutorials, but I can't get it to work. I want to play Frame 2 when the black circle (character) hits the red square (hitbox). If someone could try some code in there, and find something that works, I would be very grateful. The file is attached.
Collision Detection
i have looked at flashkit, macromedia help, and some more things, each one gives me a code, alwase the same, but when i put it in my movie it dosent work, my two coliding movie clips are "a" and "b" this is my code
if (a.hitTest(b))
action
1. what is wrong with that?
2. maby im putting the code in the wrong place, so where should i put it?
I Think This Has To Do With Collision Detection
I'm not sure but how would I go about making it possible to make a character your moving with the keyboard walk into a door to a house and upon the character touching the door the screen would change to the interior of the house? If there is a tutorial on this subject point me in that direction, but I wouldn't know what to search for to find this.
Collision Detection
Hi. I'm actually developing an adventure game in flash. The character movement has been programmed. For the collision detection, I would like to ask something. Should I include the collision detection code inside together with the character movement code or include into the map or into another separate frame? By the way, I really need your help. The map I have designed is actually divided into 6 parts namely top left, top middle, top right, bottom left, bottom middle and bottom right. Each part has the size of 550 X 400 pixel. Do u guys have any code for the collision detection for the map? I'm really confused and badly need your help. If there is any, I would be really grateful to you. By the way, could you guys kindly include some comments in it so that I could understand the coding purpose? Thanks alot....
Help With A Certain Collision Detection...
I have this new file i am working on, I shouldnt put it in games because I think it can be solved very easily, it's just help with making the ball not sink into the platform. You can see it easier with this file attached.
The ball sinks into the platform in which it is supposed to bounce on.
Collision Detection Help
i need some help with my collision detection. i thought that i had the code all right but i dont. here is my code:
if (_root.lemon, hitTest(_root.player)) {
gotoAndPlay("gameover")
lemon = my enemy that the code is on
player = me...
"gameover" = the frame that it goes to and plays...
Collision Detection
Hi there!!
I would like to find out how to test a collision detection of two or more circles.
If anyone knows how to do it, please give me a hint.
Collision Detection Help
I'm more than a little stuck as to how to sort out this problem with collision detection I have for a game I intend to make / remake, using flash to sort out the logic problems involved with such matters as collision.
My problem is determining what course of action to take when bouncing off a wall. (see attachment for details)
The simple types are vertical and horizontal walls but sorting out corners appears to be a tricky one, what with there being so many types of them!!
Using Flash MX and actionscript 1.0... or is it 1.1, well it's not 2.0
Collision Detection Help
I made a simple scene where there is a space ship and meteors flying towards the spaceship. The objective is that we drag the space ship out of the way of the meteors and if we don't it would detect the collision and go to the next frame. I made a normal movie clip as my spaceship and the meteor is also s movie clip but inside of the mc it has the animation of the meteors flying by!
All i done so far was the start drag:
on (press) {
this.startDrag()
tried this but it didn't work:
if (this.hitTest(_root.meteor_mc, _root.meteor_mc, true))
trace("hitTest true");
PLEASE CAN SOMEBODY HELP ME! I would like to put the fla file but i don't know how.
Collision Detection.
does any one know how to do it so that when the square is over the circle although it is set to true i would like an action to happen such as jumping to the next scene? I have put my file attached below, if anyone has any ideas. Thank you.
Collision Detection
hi
I have 2 objects and i am duplicating thosse two object and moving then in their oposite direction so they will collide to each other. my problem is that i am not been able to dectect which object colided with which one.
Thanx in aqvance for any sort of help provided to me
[F8] Car Collision Detection
right now the collision detection sucks it just bounces back and it is glitchy.
it just checks 4 points to see if the car has hit a wall. Is there a tutorial on how to make better collision detection?
Help With Collision Detection
hi guys
I want to create a collision detention system where objects move away from each other if they get too close, much like in the link below (done in java I think):
http://www.aharef.info/static/htmlgr...joeprice.co.uk
Could anyone point me in the direction of a potential tutorial for achieving collision detection along these lines?
Many many thanks for your responses
Joe
[AS2 On CS3] Collision Detection
What is the sytax for detecting a collision for:
two movie clips on stage, blue_mc and red_mc. If they collide I want the output window tp read "hit"
Collision Detection Help
What i am trying to do is make a bunch of objects able to be arranged on a screen kind of like a customizable preview layout. Although i have objects that i don't want to be able to overlap.
If i have 3 boxes spread out on the stage and i move one i want it to detect if i overlap one to stop and not let me overlap it. I basically need a collision detection script. The issue is all three boxes can be dragged so it can't be just set values it has to be constantly updatable so that if i move one object (box 1) then move (box 2) it has to detect the position and see if it overlaps and if so not let drag any further.
Any help would greatly be appreciated.
Collision Detection
i'm trying to add collision detection to my bubble, but i can't figure it out.
can someone make me an example of this:
the bubble can't come in the red zone:
i use this code:
Code:
import flash.geom.Point;
bubbel.onEnterFrame = moveBubble;
bubbel.vx = 0;
bubbel.vy = 0;
var decay:Number = 0.95;
var maxSpeed:Number = 30;
var minDistance:Number = 150;
this.onMouseDown = function() {
this.onEnterFrame = blow;
};
this.onMouseUp = function() {
this.onEnterFrame = null;
};
function blow() {
var startP:Point = new Point(bubbel._x, bubbel._y);
var endP:Point = new Point(_xmouse, _ymouse);
var dist:Number = Point.distance(startP, endP);
var distY:Number = bubbel._y-_ymouse;
var distX:Number = bubbel._x-_xmouse;
if (dist<minDistance) {
var speed:Number = (minDistance-dist)/minDistance*maxSpeed;
var angle:Number = Math.atan2(distY, distX);
bubbel.vx += Math.cos(angle)*speed;
bubbel.vy += Math.sin(angle)*speed;
}
}
function moveBubble() {
this._x += this.vx;
this._y += this.vy;
this.vx *= decay;
this.vy *= decay;
if (this._x<this._width/2) {
this._x = this._width/2;
}
if (this._x>Stage.width-this._width/2) {
this._x = Stage.width-this._width/2;
}
if (this._y<this._height/2) {
this._y = this._height/2;
}
if (this._y>Stage.height-this._height/2) {
this._y = Stage.height-this._height/2;
}
}
[cs3] Collision Detection
Here is what I have. Right now I am creating 40 objects with shapes randomly chosen from the library. They move around the screen and bounce of the edges randomly. I also have an object that follows the mouse. I want to be able to detect when the mouse object *not the mouse* comes in contact with one of the 40 objects.
Here is what I haVe tried:
Code:
var basicUnits = 0;
//Places different objects from the library into an array and places them onto the stage.
var tmi = 40;
var instanceNames = new Array("enemy1", "enemy2", "enemy3", "enemy4", "enemy5", "enemy6", "enemy7", "enemy8");
var collisionList = new Array();
for (i=1; i<=tmi; i++) {
var libraryId = instanceNames[random(instanceNames.length)];
_root.attachMovie( libraryId , "circle"+i, i, {x:200, y:50});
collisionList = (i, "circle"+i);
basicUnits++;
}
Code:
//Beginning of collision detection code.
var ship_x = GetProperty ("/ship",_x);
var ship_y = GetProperty ("/ship",_y);
var obj;
for(p = 0; p <= tmi; p++){
//collisionList was created aboe
obj = collisionList[p];
var obj_x = "circle"+ p._x;
var obj_y = "circle" + p._y;
var ship_h = getProperty("ship", _height) / 2;
var obj_h = getProperty("circle" + p, _height) / 2;
var ship_w = getProperty("ship", _width) / 2;
var obj_w = getProperty("circle" + p, _width) / 2;
var distance_x = ship_x-obj_x;
var distance_y = ship_y-obj_y;
var area = (ship_h+ship_w)*(obj_h+obj_w);
if ((distance_x * distance_x) + (distance_y * distance_y) <= area){
trace("collision detected");
}
else{
trace("no collision");
}
}
Right now my trace is constantly reading as "collision detected", even when the mouse object is near nothing. I am going to upload the file, because there is a lot of other code that may be interfering with what I'm trying to do, and I'm not very skilled with Actionscript, so it may help to see everything in the file.
Would there be an easier way to detect collision between these objects? Or why is my code not working. Thank you.
[CS3] [AS2] Collision Detection.
Hello,
I wanted to know if there is a way with which I can get the names of objects hitting another object.
Suppose I have a box and three circles (draggable) on stage. Now, suppose user drags all three circles on the box, I get an Array with a list of their instance names...?
I know how to detect collisions. mc.hitTest(mc2) etc. .. But the situation is that I have to get the a list of object's names which are currently touching the other specific object...
is that possible?
[F8] Collision Detection
Ok, I know you can use hitTest to test an object against a specific movie clip, but say I want to test one object to see if it hits ANY movie clips, how would I do that?
|