View Full Version : problems w/ my function... [MX]
zylum
March 28th, 2003, 06:03 PM
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...
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;
};
can anyone find a mistake with my AS? it's probably something stupid...
-mike
senocular
March 28th, 2003, 06:06 PM
"it's probably something stupid..."
yes, yes it is ;)
you are adding the .2 before you actually set dy. That means the += .2 is useless. put dy += .2 AFTER you set dy
zylum
March 28th, 2003, 09:06 PM
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...:P
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;
}
};
hope you guys can find something...
-mike
ahmed
March 28th, 2003, 10:25 PM
someone mentioned on the forums that you cant incremate a variable by a value smaller than .5... i'll check for the link :)
ahmed
March 28th, 2003, 10:27 PM
here.. see sinfiniti's post :)
http://www.kirupaforum.com/forums/showthread.php?s=&threadid=16877&highlight=0.5
zylum
March 28th, 2003, 10:42 PM
nope, that's not it... i tried 0.5 , 1 and 2... none of them work.:P
zylum
March 29th, 2003, 06:58 PM
maybe it's got something to do with the fact that the function is set in an if statemen?
if (Key.isDown(Key.SPACE)) {
shoot += 1;
}
if (shoot>0) {
ball.onEnterFrame = sht;
}
sht is the function that causes the ball to move in the proper direction :
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;
};
is that the problem? and if it is, how can i overcome it?
- Michael
Marz
March 30th, 2003, 07:34 AM
if (Key.isDown(Key.SPACE)) {
shoot += 1;
}
if (shoot>0) {
sht;
}
Errm.. You don't even need the ball.onEnterFrame statement.. Just call the function my main man ;)
playamarz
Marz
March 30th, 2003, 07:36 AM
Also... While I'm at it.. You might wanna move the ball to the end of your barrel as soon as someone shoots like that then.. :)
playamarz
zylum
March 30th, 2003, 01:44 PM
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???
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.