views:

135

answers:

1

Say I have a movie clip that when loaded I set it's .z position to 2000 to make it look far off in the background... How in the world can I set it's x and y points with any certainty as to where it will appear on the stage? Is there an equation?

E.g.;

original.x = 200;
original.y = 200;
original.z = 0;

new.z = 2000;
new.x = original.x*10;
new.y = original.y*10;
+1  A: 

you have to seperate out the actual x and y points with the 3D space points (i use _x, _y and _z). using a basic idea that anything further away from you is going to be you will need to define an origin for the vanishing point and a "focal length" (think of a camera lens) that will define how quickly things dissappear into the background. try playing with values, but something around 200 usually works fairly well. this should give you something simple like this where my_mc is the object you want to have the effect on:

my_mc._x = 0; 
my_mc._y = 0; 
my_mc._z = 200;
var scaleRatio = focalLength/(focalLength + my_mc._z);
my_mc.x = origin.x + my_mc._x * scaleRatio;
my_mc.y = origin.y + my_mc._y * scaleRatio;
my_mc.scaleX = my_mc.scaleY = scaleRatio;

there are some really good tutorials at kirupa on this subject, try this one (though it is in as2 the theory is the same) http://www.kirupa.com/developer/actionscript/3dexplore.htm

shortstick
Thanks for the heads up. I've actually seen that tutorial and was looking for a shortcut. Maybe a simple equation where I can at least have control over where my z-scaled object is on the stage. I've really got to look at it with the other side of my brain I guess.
Jascha
well if you are after just a "false perspective" then you can do that just with the scale function on the z, it depends on your usage really. That is as far as ive found the simplest "3D" simulator though.
shortstick