-
Asteroids! Toroidal Topology with expressions?
Hello there,
I’m looking to do something with expressions that I thought would be rather easier. What I want to recreate is the look of the old “Asteroids” game, which uses “toroidal topology” – a fancy way of saying that when objects reach the top of the screen, they re-appear at the bottom. The same goes for left-right, right-left and bottom-top.
I have this really simple bit of positioning script which allows causes layers to move continuously with the help of a couple of sliders:
v = effect("Slider Control x")("Slider");
w = effect("Slider Control y")("Slider");f = timeToFrames();
f0 = timeToFrames(inPoint) + 1;
myValx = 0;
myValy = 0;for ( i = f0 ; i <= f ; i ++){
t = framesToTime(i);
myValx += v.valueAtTime(t);
myValy += w.valueAtTime(t);
}value + [myValx,myValy]
I haven’t set any keyframes for the sliders because I’m happy for the asteroids to move at a constant rate. I can just duplicate the asteroids, tweak the sliders for each and off they go. The problem is that because the code doesn’t actually change the value of position[0] and position[1] I can’t tell it to wrap-around the position when it reaches edge of frame:
if (position[0] >= 720){position[0] == 10;}
if (position[0] <= 0){position[0] == 710;} ……………….etc, won’t work.What I need is something that takes the value of x, plus or minus the value of myValx depending on which direction it’s going, subtracts this from the distance to the edge of the screen and then adjusts myValx accordingly to move it to the other side of the screen. It is at this point that my head starts to go around and around in circles like that of Colonel Dedshott when Professor Branestawm starts explaining one of his inventions.
Can anyone help me with this, or suggest a better way of doing it?
I would be most awfully grateful.
Jason Guest