# Problems w/ my function... \[MX\]

**URL:** <https://forum.kirupa.com/t/problems-w-my-function-mx/16846>\
**Category:** Uncategorized\
**Created:** [March 28, 2003, 11:03pm UTC](https://forum.kirupa.com/t/problems-w-my-function-mx/16846 "2003-03-28T23:03:17Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![zylum](https://avatars.discourse-cdn.com/v4/letter/z/d26b3c/32.png) [@zylum](https://forum.kirupa.com/u/zylum)\
**Post date:** [March 28, 2003, 11:03pm UTC](https://forum.kirupa.com/t/problems-w-my-function-mx/16846/1 "2003-03-28T23:03:17Z")

</div>

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…

-mike

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 28, 2003, 11:06pm UTC](https://forum.kirupa.com/t/problems-w-my-function-mx/16846/2 "2003-03-28T23:06:57Z")

</div>

_“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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 29, 2003, 2:06am UTC](https://forum.kirupa.com/t/problems-w-my-function-mx/16846/3 "2003-03-29T02:06:50Z")

</div>

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]

hope you guys can find something…

-mike

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 29, 2003, 3:25am UTC](https://forum.kirupa.com/t/problems-w-my-function-mx/16846/4 "2003-03-29T03:25:26Z")

</div>

someone mentioned on the forums that you cant incremate a variable by a value smaller than .5… i’ll check for the link 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 29, 2003, 3:27am UTC](https://forum.kirupa.com/t/problems-w-my-function-mx/16846/5 "2003-03-29T03:27:55Z")

</div>

here… see sinfiniti’s post 🙂

[http://www.kirupaforum.com/forums/showthread.php?s=&threadid=16877&highlight=0.5](http://www.kirupaforum.com/forums/showthread.php?s=&threadid=16877&highlight=0.5)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 29, 2003, 3:42am UTC](https://forum.kirupa.com/t/problems-w-my-function-mx/16846/6 "2003-03-29T03:42:14Z")

</div>

nope, that’s not it… i tried 0.5 , 1 and 2… none of them work.😛

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 29, 2003, 11:58pm UTC](https://forum.kirupa.com/t/problems-w-my-function-mx/16846/7 "2003-03-29T23:58:11Z")

</div>

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?

- Michael

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 30, 2003, 12:34pm UTC](https://forum.kirupa.com/t/problems-w-my-function-mx/16846/8 "2003-03-30T12:34:15Z")

</div>

[AS]  
if (Key.isDown(Key.SPACE)) {  
shoot += 1;  
}  
if (shoot\>0) {  
sht;  
}  
[/AS]

Errm… You don’t even need the ball.onEnterFrame statement… Just call the function my main man 😉

playamarz

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 30, 2003, 12:36pm UTC](https://forum.kirupa.com/t/problems-w-my-function-mx/16846/9 "2003-03-30T12:36:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 30, 2003, 6:44pm UTC](https://forum.kirupa.com/t/problems-w-my-function-mx/16846/10 "2003-03-30T18:44:15Z")

</div>

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???
