Flash MX GRAVITY
Hello,
It's very interesting the tutorial about gravity
http://www.kirupa.com/developer/acti...pt/gravity.htm
I would like to know how to do this exercise with several balls falling down randomly.
Thanks for your help.
KirupaForum > Flash > Flash 8 (and earlier) > Flash MX
Posted on: 08-27-2003, 06:24 AM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
[CS3] [AS3]Creating A Gravity Simulator In Flash
I am trying to create a gravity simulator in flash but have encountered a problem...The formula i'm trying to use is obviously:
F = GmM/ r^2
F = Force on the body
G = gravitational constant
m = mass of body 1
M = mass of body 2
r = distance between the two bodies
This is what i have in the coding so far.
Code:
onClipEvent (enterFrame) {
xdist = Math.round(_root.Ball_MC._x-this._x);
ydist = Math.round(_root.Ball_MC._y-this._y);
distancefromthis = Math.round(Math.sqrt((xdist*xdist)+(ydist*ydist)));
var forceplanet = Math.round((gravity*planetmass*sunmass)/(distancefromthis*distancefromthis))
_root.textbox1.force = _root.Planet.forceplanet;
}
Too see if my coding works i'm trying to make the textbox equal the variable forceplanet, but for some reason is blank when i run the test. Any help is appreciated thx!
Attached is the fla.
Here's the fla
Gravity
I have a problem creating a gravity effect on my movie clips, i need to know how this effect works from scratch.
Gravity
hi all Steve here aka positivdirection.
building this new flash site thats going to rock, but need a little pointer into the one cool effect and how it's done.
the effect is when an object follows the mouse it follows very slowly or moves quickly ahead as if it's reading the mouse movements but in slow mo or high speed.
I understand the parts of draggable objects, lockcenter and my defined areas and so forth, but just need a little help with some gravity. Tutorials, advice anyone?
Thank you
Gravity
Does anyone here know how to make a floating object? like a ufo, floating on the same spot??
pleease help!!!
thanks!!!
=)
Using Gravity
Hi all
I am trying to create a movie where when it loads a ball is stationary. When you mouse over the object falls to the ground and bounces (gravity type effect). Once it has stopped bouncing, another mouse over will cause it to float back to the roof and bounce again (anti gravity type effect).
I can't really seem to get my head around it so can anyone please help
many thanks
DAN
Gravity
hi,
I've been playing with actionscript for a while. I can understand most scripts...and I think I pretty much learned all the objects, methods and functions. But still I have a really hard time implementing cool scripts. For instance Gravity. I noticed theres always a crazy function involved and they all have similar parameters(friction, speed). Is there a tutorial or something anywhere that explain some of these scripts or does the average joe just invent it?
GRAVITY
ok i need to know how to apply basic gravity to a movie clip, nothing fancy jsut some action script on the MC, please help?!
Gravity
How do I make gravity on movieclips? Does it exist un EASY way?
Gravity MC
Hello,
i have a MC and i want to make it fall to a certain level and then bounce until it stops. Like a Ball falling in the ground.
Does anyone knows any good code that does this?
Thanks,
Miguel
Gravity
I've created mc - gravity ball. Whatever I do it still doesn't work. Is there somebody who can find the mistake, please?
Thanks.
Gravity
I've created mc - gravity ball. Whatever I do it still doesn't work. Is there somebody who can find the mistake, please?
Thanks.
Gravity
I've created mc - gravity ball. Whatever I do it still doesn't work. Is there somebody who can find the mistake, please?
Thanks.
Gravity
I need to learn how I can use gravity for stuff like a spaceship game, my ultimate goal is something like this, http://www.miniclip.com/gravity.htm
although I realize that I need some more experience first, I just want to know how to do gravity in that style. Does anyone know where there is a good tutorial?
Gravity
Say if i was in a level, I wanted my character to fall if he fell off a cliff (or something similar to it), how would I make it happen?
Gravity
I'm trying to use the gravity effect to bring in two boxes, one from the top and one from the bottom. I can get the one at the top to drop and rest at a certain point, but im having difficulty in getting the one at the bottom to rest as i want it to go up rather than go down. I've attached the file, hopefully it will explain more.
[Help] Gravity?
http://freewebs.com/ashentwilight/kopter.swf
http://freewebs.com/ashentwilight/kopter.fla
1.) How can I add gravity to this game?
2.) How can I move the function of the up arrow to the left mouse button?
Thanks in advance.
Gravity, Or Something Else?
i am building a fighting/adventure game called "Way of the evil Ninja"
it's going pretty good except for one thing,
i need to have some sort of action that makes the character, namely the ninja, fall to the ground if in the air.
gravity scripts don't work because im using getBounds scripts to set boundaries for the ninja and gravity scripts make the character bounce up and down.
Please, I know you people don't favor donating scripts but,
please help me.
thanks.
Gravity
Hi All,
I am a student at university who is using Flash 8 as part of a course. I have seen many examples on the internet of how gravity can work in a side on view (such as a platform game).
I am trying to make a game that has a top down view with a planet in the centre of the screen (with a gravitional pull) and a spaceship (user controlled). The idea is that while the gravity effects the ship it should be able break away from the gravity as long as it is not too close. The game should hopefully be similar to a very old computer game called "spacewar".
I have a function called calc_distance which allows me to work out how much gravitional pull there should be but its actually implementing it that i am totally lost with.
I have included a remake of space war that I found (I do not understand the code and it also seems like there is alot of it.) and my code.
If anybody has some ideas or knows a tutorial that would help please let me know, it would be most usful.
Regards
David
Gravity
one of the problems with being a 13 year old programmer:
you havent learnt the maths for a lot of stuff
im making a top-down 2D space game, and i need a gravity engine that will handle attaraction between 2 objects, like if you fly in the vicinity of a planets/moon/sun/whatever, you get pulled towards ita bit, and it affects your course and momentum.
the ship movmeent engine i am using, is an extended version of the one xeef gave me the other day, its posted below
if possible, so as to make the data packets smaller (for this is a multiplayer game), i need the gravity engine to affect the MX, MV, Ts and TV variables, otherwise use a diffrent system, up to you
here is xeef's engine
onClipEvent (load) {
maxspeed = 10;
energycost = 3;
maxcharge = 100;
rechargerate = 0.1;
energy = maxcharge;
TS = 0;
TV = 0;
MS = 0;
MV = 0;
speed = 0.053;
rotspeed = 4;
}
onClipEvent (enterFrame) {
energy += rechargerate;
if (energy>=maxcharge) {
energy = maxcharge;
}
count++;
mcount++;
if (Key.isDown(88) && count>=delay && energy>=energycost) {
_root.blast();
count = 0;
energy -= energycost;
}
if (Key.isDown(37)) {
this.TV -= rotspeed;
}
if (Key.isDown(39)) {
this.TV += rotspeed;
}
if (Key.isDown(38)) {
this.TS += speed;
}
this._rotation = this.TV;
TX = Math.cos(this.TV*Math.PI/180);
TY = Math.sin(this.TV*Math.PI/180);
MX = Math.cos(this.MV*Math.PI/180);
MY = Math.sin(this.MV*Math.PI/180);
ResultX = this.TS*TX+this.MS*MX;
ResultY = this.TS*TY+this.MS*MY;
Result = Math.sqrt(ResultX*ResultX+ResultY*ResultY);
ResultA = Math.atan2(ResultY, ResultX)*180/Math.PI;
this.MS = Result;
this.MV = ResultA;
if (this.MS<-maxspeed) {
this.MS = -maxspeed;
}
if (this.MS>maxspeed) {
this.MS = maxspeed;
}
this.TS += -this.TS/5;
_parent.map._x -= this.MS*MX;
_parent.map._y -= this.MS*MY;
_parent.star._x -= this.MS*MX;
_parent.star._y -= this.MS*MY;
}
well, thats the bit of the cvode that handles movement, minus large quantities of other stuff to do with the netowoirking
thanks for your help!
Gravity/following
What I'm looking to do isn't quite gravity but sort of. If I have 5 bottons on the bottom of the screen I want to mouse by them and they gravitate towards the mouse.
Lets say I have a square 100px X 100px I would like an area around that about 150px X 150px when I get in to the 150px area I would like the 100px square to follow the mouse. When I mouse out I would like it to snap back to its original position and bouce slowly to a stop.
Any help would be great.
if you want to slap someone around goto www.kemurshel.com
http://www.kemurshel.com/version4
Gravity
Hello everyone!
I want to apply gravity to a "MouseDown = function" object (movie clip) but I'm not sure how to.
Does anyone know the actionscript code for gravity?
Thanks a lot.
Gravity...
i have created a gravity simulator, but i want to make it so you can change whether the gravity is towards the bottom or the side, i know which bit you need to change but i do not know how to do it so that it changes when you press a button
the bit in bold is what needs to be adapted, from:
yspeed1 = yspeed*drag+gravity;
xspeed1 = xspeed*drag;
where the gravity is to the bottom,
to:
yspeed1 = yspeed*drag;
xspeed1 = xspeed*drag+gravity;
where it is at the side
if (!dragging) {
_x = _x+xspeed;
if (_x+_width/2>rightedge) {
_x = rightedge-_width/2;
xspeed = -xspeed*bounce;
}
if (_x-_width/2<leftedge) {
_x = leftedge+_width/2;
xspeed = -xspeed*bounce;
}
_y = _y+yspeed;
if (_y+_height/2>bottomedge) {
_y = bottomedge-_height/2;
yspeed = -yspeed*bounce;
}
if (_y-_height/2<topedge) {
_y = topedge+_height/2;
yspeed = -yspeed*bounce;
}
yspeed1 = yspeed*drag+gravity;
xspeed1 = xspeed*drag;
} else {
xspeed=_x-oldx;
yspeed=_y-oldy;
oldx=_x;
oldy=_y;
}
Gravity
If it's not -too- confusing, could someone explain how to use gravity in AS?
Gravity Question
Okay, sorry for posting so much on so many topics, but I'm going through a major information load over here, and I don't wanna stop.
Here is my code:
onClipEvent(load) {
gravity = 1.5;
speed = 0;
}
onClipEvent(enterFrame) {
speed += gravity;
this._y += speed;
}
Tell me something, WHY is it that the above code accelerates, and the code below doesn't??? For some reason, to me, the code below is exactly the same. Where is the difference? I can't seem to understand why it's so different.
onClipEvent(load) {
gravity = 1.5;
}
onClipEvent(enterFrame) {
this._y += gravity;
}
Riki
Gravity Tutorials
Are there any tutorials on how to create the effect of gravity - eg. the movie where you drag the ball and throw it and it bounces about. Thanks for reading this
Hittest W/ Gravity?
ok i got a bar, it randomly _yscales so that it looks like its one of them music bars, yanno that move up n down yada yada, anyway, I want to have a lil line ahead of the bar, when the bar reaches up to move the lil line up, when the ball goes down i want to apply gravity to it and have it slowly fall until hit up again by the bar, all my efforts have failed, anyone give any help/advice?
MOVEMENT + GRAVITY
hey, i was just wondering how to get movement with actionscript for like games, and also how do you get gravity in flash?
Angles, Gravity And The Like
hi im making a athletics game ive sorted the running events, now Im onto the thrown events (ie javlin,shot,longjump)My problem is ive never touched this side of flash before, could anyone suggest any tutorials or reading which could point me in the right direction
Gravity Question
trying to figure out the whole way to do something falling to earth without motion tweening. anyone have a good script for such a thing. thanks.
Gravity Effect
Hello fellas,
I am pretty new in flash and try and come with my own idea..but the fact that flashkit is such a helpful resource for new flash players you tend to learn from exp designers.
I have a query about the gravity look.
I am not too sure how to explain it.but the look somewhat goes like this:
Lets say you have a object and you want that object to come in slowly and then leave fast.
Example:http://www.nethead.com.au/
IF you see the way the text come and go.I know I can do that by controlling the motion tween.But it doesnt seem to give me the same effect.If someone could explain or send me a .swf it would be really helpful.
Thanking to all you gurus in advance
__________________
Forget the past and create the future..
Futute is the game we all look forward to play..
Simulating Gravity
I have four movieclips. Each one is a book (graphically).
I have the all as draggable, so that any one can be put on top.
If I remove one from the stack, how can I make all the others fall down (like gravity)?
_____________________________________________
I've never had this much trouble getting an answer at FlashKit. Fo I have to put HELP...HELP...HELP...HELP...HELP...HELP... in my subject line just to get some "HELP...?"
Please, any tidbit of info to get me on the right track is greatly appreciated.
[Edited by junethesis on 03-07-2002 at 09:18 PM]
Gravity Function
Hi,
does anyone knows a function to make a MC fall with gravity and bounce when it arrives to the ground?
Thanks,
Miguel
Adding Gravity
can anyone please help me work out how to make a ball have a gravity effect and drop to the bottom of the screen when the ball is released.
I am trying to make a bouncing ball interface and have managed to get the ball moving to the speed of the mouse once released. Once the ball is released it will slow down till it stops. And will bounce randomly round the screen. All i want to do is to keep this random boncing effect and de-acceleration, BUT, the ball drops to the floor giving it a gravity effect. I have managed to get the ball_mc (the ball) coming down to the floor, but it does not bounce and slowly come to a stop.
Basically im trying to get a similar effect to the www.jellyweb.com interface, that im sure alot of you are familiar with ( if not check it out its cool).
My actionscript is below, any suggestions would be great, thanks
ball_mc.onPress = function(){
this.startDrag();
this.onEnterFrame = function(){
this.oldX = this.newX;
this.oldY = this.newY;
this.newX = this._x;
this.newY = this._y;
}
}
ball_mc.onRelease = function(){
this.stopDrag();
this.speedX = (this.newX - this.oldX) * this.ratio;
this.speedY = (this.newY - this.oldY) * this.ratio;
// ignore this is for a drap and menu
//if (eval(this._droptarget) == _root.drop_target){
//unloadMovieNum (1);
//loadMovieNum("the_about_us.swf", 1);
//_level3.gotoAndPlay(1);
}
this.onEnterFrame = function(){
this.speedX *= this.friction;
this.speedY *= this.friction;
this._x += this.speedX;
this._y += this.speedY;
this.checkWalls();
}
}
ball_mc.onReleaseOutside = ball_mc.onRelease;
ball_mc.checkWalls = function() {
if (this._x < (WALLLEFT + this.radius)) {
//reset the position of the ball inside the bounds
this._x = ((WALLLEFT + this.radius) - this._x) + WALLLEFT + this.radius;
//Reverse the speed
this.speedX *= -1;
}
if (this._x > (WALLRIGHT - this.radius)) {
//reset the position of the ball inside the bounds
this._x = ((WALLRIGHT - this.radius) - this._x) + WALLRIGHT - this.radius;
//Reverse the speed
this.speedX *= -1;
}
if (this._y < (WALLTOP + this.radius)) {
//reset the position of the ball inside the bounds
this._y = ((WALLTOP + this.radius) - this._y) + WALLTOP + this.radius;
//Reverse the speed
this.speedY *= -1;
}
if (this._y > (WALLBOTTOM - this.radius)) {
//reset the position of the ball inside the bounds
this._y = ((WALLBOTTOM - this.radius) - this._y) + WALLBOTTOM - this.radius;
//Reverse the speed
this.speedY *= -1;
}
}
//determine the radius of the ball
ball_mc.radius = ball_mc._width/2;
_global.WALLLEFT = 50;
_global.WALLRIGHT = 712;
_global.WALLTOP = 92;
_global.WALLBOTTOM = 359;
ball_mc.friction = .9;
ball_mc.ratio = .5;
ball_mc.newX = ball_mc._x;
ball_mc.oldX = ball_mc._x;
ball_mc.newY = ball_mc._y;
ball_mc.oldY = ball_mc._y;
ball_mc.speedX = 0;
ball_mc.speedY = 0;
Understanding Gravity
I started a simple movie using gravity. Check the fla file.
I'd like to know two things (initially):
1) Why does the little ball buries itself in the grass? how can I avoid it?
2) I know why if I keep pressed UP the ball flies and flies up, but I'd like to make it jump and fall... how?
PS: I know there may be lots of other posts on gravity, but Im just playing a bit and try to figure out things by my self (though Im asking for help here hehe). Anyway, I'll check those post later when Ive got the idea.
Gravity Ball
I've created mc - gravity ball. Whatever I do it still doesn't work. Is there somebody who can find the mistake?
Thanks.
Gravity Effect
how do u make a spaceship in a game like the helicopter game on addictinggames.com, where the helicopter automatically falls down (a gravity effect)
Gravity...platforms..
how do you make there be like...gravity, and have platforms for a dude to jump on? Ya know what I mean?
Having Issues With GRAVITY Plz Help
hey guys...here is a link to my files (1 swf, 1 fla) what i am trying to do is have the button at the top of the page triggerso that it drops a new ball, leaving the initial one still on the stage and interactable...basically i want the top button to generate another (not a new) ball, so that if the viewer wants he/she may have tens of balls to play with on the stage (yes, yes...get it out...i said 'tens of balls to play with')...ok so if you are willing to take a look at my files, all this will make sense...thx peeps!
tens of balls (the files)
Gravity Script
i'm new to flash and am making a catching game.
looking for a simple script to make objects fall and disappear when they intersect with the 'catching' object.
also need to monitor this by a status symbol filling with colour.
how do i do this???!!
I can't seem to find my way around the 'movies' section of this site to find the game code i need.
help would be much appreciated!
Gravity... Problems
Alright, jbum's been helping me out with this so far,
I can see why this is happeneing.. I just don't know what to replace it with to make it work the way I would like..
basically depending on the ammount of time you hold down the button.. the ball will launch with a certain velocity
now.. I want the ball to continue in that direction after being launched.. as in gravity will take it down on the left side of the stage...
right now it will follow its linear path back to the right side..
anyone?
Advanced Gravity Help
I figure out how to make gravity without using math, and I need help using hitest(x) or hittest(y) to stop the falling object and to reset it at its original starting position.
PS The file uses MX (not mx 2004)
How To Add Gravity And Jumping
i am trying to make a simple platforming game but in the tutorials i cant find a place to set up jumping. for the jumping i just want my thing to go up a little bit then come back down but i have no idea how to do this because i just started with actionscripting. (i found gravity tutorials but i lost it) so...any help?
Gravity Effect
Does anyone know how to make the gravity effect that they have on this page . (http://volumeone.com/seasons/17/index.html)
I use to have the script but stupid me, i joined the army for 3 years and lost everything. Can someone help me please.
thanks
Donald
Gravity Is Glitching
I've got a hoepfully simple question i was trying to make this "imitation of gravity type thing with bouncey balls, which i have seen before so i devloped my own script to try this, it all works fine except when you drag the ball and throw it sometimes if you throw it too hard it gets kind of "stuck" on the barrier. Then eventually it will pop back out which i think has something to do witht he script about making it not pass a certain point, well here is the fla thanks
Collision And Gravity...how?
Hi I need a hand with an effect I'm trying to create.
Basically what I need to produce is a box full of marbles. Imagine the box starting to swell as though more marbles are being added or as though they are growing. Eventually the corner snaps/breaks open and all the marbles start to fall out, filling another box below the break.
Now how would I do that?
I'm guessing I would need to create a collision detection and a gravity engine.
Can someone give me some code to set me off in the right direction or maybe point me towards an FLA I can download?
Thanks for your help.
Physics And Gravity [help]
I was trying to make a trail on this simple shooter. So it'll show the parobolic path the bullet takes. However, it does some weird things. The first bullet duplicated gets romoved evey time you shoot. No idea why. FLA is posted.
Collisions And Gravity...
I currently have a working gravity script, but what I want to do is kind of a particle system where you can drop the things you want like snow, sand and the like, like in this.
I want particles to be able to slide on others when they collide and make a stack, if you see what I mean.
Thanks!
[F8] Gravity Function
so i was into flash/actionscript for about a year, and that was around 2 years ago. since then ive forgotten allot of what i knew about actionscript. i still know the math to do most the stuff i would like to do, yet i have forgotten most the syntax involved. what i did last night was creat a function that you give the propertys of the instance name
Code:
gravity(ball);
but stupidly i forgot that if i want to use this on multiple objects, they all need to have there own variables for xspeed and yspeed, otherwise they will all move the same. i tryed somthing along the lines of
Code:
var _root[what].speedx;
trying to see if i could possibly create a variable in the object, but that didn't work. so now since i cant create a variable in a function that will live thru the whole movie and only in the instance its being called, im stuck. im pretty sure im going about this all wrong and there is a simpler way to do it. ultimately i want to be able to give an object a property that will give it gravity, instead of just puting the gravity code on every movie clip, thats just too messy for me. so im here to ask, does anyone know of a way to acomplish what i need to do?
dpsleep
Help With My Gravity Code
hello all.
I've come up with this little piece of simple gravity code
Code:
var yfall = 0
var grav = 0.3
function onEnterFrame(){
yfall = yfall + grav
if(_y + yfall > 755){
yfall =- yfall*0.65
}
_y = _y + yfall
}
}
This is in a separate .as file to my movie and as items from my movie are randomly generated from an array these physics properties are then applied dynamically to the randomly generated clips.
What i would really like to do is have the clips explode out in a set arc shooting upwards before being pulled down by gravity.
Two questions:
1) How would i get the clips to go up before the physics code kicks in?
2) How do i get the clips to fall at a random angle?
I thought the random angle code might look something like this:
Code:
random:Number = 270*(Math.PI/180);
But that dose not seem to work.
Any ideas?
Thanks.
|