PDA

View Full Version : [Flash] gravity actionscript help



DarkCloud
12-23-2009, 10:38 PM
ok so i'm trying to create gravity for a ball heres the code
onClipEvent(load){
gravity=2;
}
onClipEvent(enterFrame){
vy += gravity;
} but when I load it the ball just stays in midair can you guys help.:Nooooooo:

CGIllusion
12-23-2009, 11:54 PM
Aren't you supposed to do something like ball.y += gravity? Whats vy?

DarkCloud
12-24-2009, 12:21 AM
V is for velocity :heh: anyways anyone else help!

CGIllusion
12-24-2009, 04:37 AM
So you're just going to disregard the first part of my post. Incrementing some arbitrary variable in your frame event obviously accomplishes nothing, you have to modify the objects y axis (this._y += gravity) is the proper syntax I believe.

Scorpioxxx
12-24-2009, 06:21 AM
I scanned through the tutorial he used, vy is the variable for the change in the y axis, like you said he just hasn't applied it to anything.

Try something along these lines, however, you'll have to fill in the blanks/replace the italic bold text:


onClipEvent(load){
gravity = 2;
vy = 0
}
onClipEvent(enterFrame){
if (vy < max gravity strength) {
vy += gravity;
}
_root.instance name of ball.y -= vy
}

My AS2 might be a bit rusty since I've been learning AS3 and might have used some of that in place of AS2 but you should be able to clean it out by googling it. This includes a way to give the dropping speed of the ball a maximum, eg, 10.

_root.instance name of ball.y could be replaced with this.y but that will be a bitch if you every advance to AS3 as it was removed, kind of anyway.

Aycaramba
12-24-2009, 07:59 AM
It's ._y in AS2.
DarkCloud, try learning more basic stuff, and don't move on to more advanced stuff until you understand the code.

DarkCloud
12-24-2009, 03:53 PM
I feel stupid I still don't understand it...

Aycaramba
12-24-2009, 04:07 PM
Did you read the tutorial Flood gave you?
If you haven't, read it.

The Dude
12-24-2009, 04:27 PM
You might want to learn about hitTests also.

DarkCloud
12-24-2009, 04:30 PM
yea I did learn heres my code idk if it works since the damn ball wont let gravity affect it!heres the hittest can you guys tell if its right

onClipEvent(enterFrame){
if (_root.ball.hitTest(_root.ground)){
vy *= 0;
vx *= 0;
}
}

Scorpioxxx
12-25-2009, 06:21 PM
If the movieclip ball hits the movieclip ground, vy and vx are * by 0, making them 0. You then do nothing with these variables so nothing will happen. To try and explain it, you have vaiables, a value or setting. You have to tell flash what to do with these, for exmaple, telling it that the ball's x co-ordinate value should equal vx.