I made a function for a ball that allows a ball to be shot at an angle (for a game) and it works fine. When I try to add gravity, no effect takes place, that is to say that there are no gravitation effects… here’s my function…
[AS] sht = function () {
dy += 0.2;
dx = Math.cos(ang)(cannon._xscale)/10;
dy = Math.sin(ang)(cannon._xscale)/10;
ball._rotation = ang*(180/Math.PI);
ball._x += dx;
ball._y += dy;
};[/AS]
can anyone find a mistake with my AS? it’s probably something stupid…
oh yea… I missed that, but, that didn’t seem to fix it. Still, there is no arc/gravitational effect even after the change… here’s the whole code maybe it’s something else that’s just as dumb…
[AS]ang = 0;
spd = 0.015;
pwr = 1;
shoot = 0;
sht = function () {
dx = Math.cos(ang)(cannon._xscale)/10;
dy = Math.sin(ang)(cannon._xscale)/10;
ball._rotation = ang*(180/Math.PI);
ball._x += dx;
ball._y += dy;
dy += 0.2;
};
onEnterFrame = function () {
// depths
cannon.swapDepths(2);
tank.swapDepths(3);
// angle of cannon
if (Key.isDown(Key.UP)) {
ang -= spd;
}
if (Key.isDown(Key.DOWN)) {
ang += spd;
}
if (ang<-3.15) {
ang = -3.15;
}
if (ang>0) {
ang = 0;
}
cannon._rotation = ang*(180/Math.PI);
// x scale of cannon
if (Key.isDown(Key.RIGHT)) {
cannon._xscale += pwr;
}
if (Key.isDown(Key.LEFT)) {
cannon._xscale -= pwr;
}
if (cannon._xscale<50) {
cannon._xscale = 50;
}
if (cannon._xscale>150) {
cannon._xscale = 150;
}
// data stuff in text boxes
power = cannon._xscale-50;
angle = Math.round((ang/3.15)*-180);
// ball movement
if (Key.isDown(Key.SPACE)) {
shoot += 1;
}
if (shoot>0) {
spd = 0;
pwr = 0;
ball.onEnterFrame = sht;
}
};[/AS]
maybe it’s got something to do with the fact that the function is set in an if statemen?
[AS]
if (Key.isDown(Key.SPACE)) {
shoot += 1;
}
if (shoot>0) {
ball.onEnterFrame = sht;
}
[/AS]
sht is the function that causes the ball to move in the proper direction :
[AS]sht = function () {
dx = Math.cos(ang)(cannon._xscale)/10;
dy = Math.sin(ang)(cannon._xscale)/10;
ball._rotation = ang*(180/Math.PI);
ball._x += dx;
ball._y += dy;
dy += 1;
};[/AS]
is that the problem? and if it is, how can i overcome it?
I tried calling the function like you told me playamarz, but it just caused things to get worse. I changed my function so that instead of “ball." I used "this.” and i left the function call as it was. when i called the function the way you told me, the ball was never shot, not to mention any gravitational effect… I’m really getting confused now:(. is there anyone who can help???