View Full Version : [AS2] distance question
xdeath
09-19-2008, 04:08 AM
can anyone tell me how i would say something like this in actionscipt 2.0:
code will be on the actual movieclip
onClipEvent(enterFrame){
if (if "p1 instance" is within a curtain distance to this (on one axis like the x or y)){
// do shooting code which i have no idea how to do.
}
}
anyone know how?
i'm not sure if you have problems with the math involved here or the code.
to get the current position of your movie clip, you can use this._x and this._y, if your movie clip (?) p1 is nested within your current movie clip you can access its coordiantes by this.p1._x and this.p1._y
xdeath
09-20-2008, 04:34 AM
i alrewady know how to call my movieclip i want to know how i can say the distance from my movieclip to another movieclip. it couldn't be that diffucult.
First, it depends on which metric you're applying. The three most popular metrics would be the Euclidean metric, the Manhattan norm, and the maximum norm ( see also at wikipedia: Euclidean distance (http://en.wikipedia.org/wiki/Euclidean_distance) and Norm (mathematics) (http://en.wikipedia.org/wiki/Norm_(mathematics)) )
Second, it depends on from which point you're calculating the distance. If you're just interested in getting the distance from the movie clips top left corners, it's quite easy. if you have some custom shapes, it can be much more difficult. if you have rectangles or circles, it's still quite easy.
So, under which conditions do you want to know the distance?
raydowe
09-21-2008, 03:57 AM
I'm not gonna use big words.
Look at this and you should get your answer.
http://www.kirupa.com/developer/actionscript/calculating_distance2.htm
xdeath
09-23-2008, 08:15 AM
the only problem with that is, that if i use that code on my ball object then as soon as it comes within that distance from anywere in the document code will be executed. but see how i want it to work is say it comes within a curtain distance of his x position so say for example there is ground and i have a ball that falls, and a box that sits on ground these 2 objects are both the same size.
now say that ball is on the ground he would be on the same x position as the box. that is what i mean when i say same x or y axis. which is why distance codes aren't working. see i've come up with this code which doesn't need to use math functions to work because i don't understand them and no one is bothering to explain them without big words so yeah here is code:
distanceX = this._x - _root.box._x
and that code was placed on my ball object in an enterframe clip event
and it works fine but still same problem as if i place the distanceX variable in an if statement to test it, it calculates it will execute it once i come within that distance from any axis.
i've tried playing around with y coordinates but because my instances are like 5 pixels or so different and there is decimal places i can't say if they are equal to one another and when i say if they are greater than this value but smaller than that it stops working all together.
um so yeah i really need help and i hoep someone will give me a working code because i'm at breaking point with this community and the whole no helping anyone as soon as there is a touch of difficulty thing it pulls on me.
raydowe
09-23-2008, 02:26 PM
That post was a lot to take in without your project in from of me. It might be easier to explain shortly and clearly what you end goal is of this application.
newblack
09-23-2008, 04:04 PM
yeah- you should just post your code. i guarantee what you're trying to do is very simple, but you completely fail at describing it...
xdeath
09-24-2008, 03:08 AM
well my code will not help i deleted my enemy once i'd spent a week trying to fix it so really all your going to see is my awesome characetr movement and collision system so if you want to see that i can show you but it's irrelevant towards my question. the game is a top-down view maze game and it's all grid based movement. hence my question on one axis.
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.