PDA

Click to See Complete Forum and Search --> : Incredibly Easy Physics and Gravity!!!!



DarkMagicHacker
09-14-2002, 04:26 PM
For all of you with questions pertaining to Physics and Gravity, here is a bug free solution to your problem!
Here are the Steps:

-> Open a new movie and set its dimensions to 550x400
-> Make a ball movie clip.
-> Go into actions
-> Type this in


onClipEvent(enterFrame)
{
// this keeps track of the ball speed.
_x = xspeed + _x;
_y = yspeed + _y;
// this slows down the ball
xspeed = xspeed*0.9;
yspeed = yspeed*0.9;
// makes dat ball bounce
if (_y>400)
{
yspeed = -yspeed;
}
if (_x>550)
{
xspeed = -xspeed;
}
else if (_x<0)
{
xspeed = -xspeed;
}
}
onClipEvent(load)
{
xspeed = 5;
yspeed = -7;
}


The solution to all physics problems!

Ed Mack
09-15-2002, 06:38 AM
There is more to physics than bouncing off walls... unless I'm not getting somthing here.

ericlin
09-15-2002, 06:57 PM
bug free solution

I did as you suggest, and make a ball _y=5; Copy your codes into the ball. Then test movie.

How come the ball goes off the screen straightly without bounce ?! I think there must be a bug in your code.

bit-101
09-15-2002, 09:57 PM
aaaah! all my problems are solved! ;)

Ed Mack
09-19-2002, 04:22 PM
Darn, it seems like your site's out of business now, eh bit?

bit-101
09-19-2002, 04:28 PM
are you kidding? with this new information, i'll be able to do crazy stuff!

Ed Mack
09-19-2002, 04:33 PM
oh you make me laugh ;)

More seriously, DarkMagicHacker, this sort of code is unsuitable for Flashkit, due to our rating. This really could blow some of the younger 13-15yr olds.

mouse111
09-30-2002, 07:22 PM
blow what?

how is it unsuitable

it may not be that great cause the bounces are not true bounces they just hit something and reverse direction at a constant speed, but how is it unsuitable

muckyMuckMan
10-01-2002, 09:14 PM
Originally posted by mouse111
blow what?

how is it unsuitable

it may not be that great cause the bounces are not true bounces they just hit something and reverse direction at a constant speed, but how is it unsuitable


Swwwoooooossshhhh!

:D

Ed Mack
10-03-2002, 03:41 PM
Originally posted by mouse111
blow what?

how is it unsuitable

it may not be that great cause the bounces are not true bounces they just hit something and reverse direction at a constant speed, but how is it unsuitable
You see, it's unfortunitly too late for some of us. Please, any parents out there, ban this thread on your computer.

WMLeeBo
10-05-2002, 10:14 PM
Whaaa...*Tries to piece together with 10th grade Geometry knowledge. 9Th grade Algerbra Knowledge.*

Brain Crashes....

mouse111
10-18-2002, 10:06 PM
Originally posted by muckyMuckMan
Swwwoooooossshhhh!

:D

ugh i understand now

its a pretty simplistic way of making a cheasy effect

o well

UnderTheSun
10-23-2002, 02:44 AM
heres' an example, with air resistance and draggable throwable ball :)

http://www.geocities.com/nohuntersweb/heheagain.html

just the unnatural stop and the tendency to keep on bouncing, which is caused by the imperfect gravity script :)

this was in the arena's actionscript battle

xDrunkCowx
10-24-2002, 01:30 AM
Originally posted by Ed Mack
oh you make me laugh ;)

More seriously, DarkMagicHacker, this sort of code is unsuitable for Flashkit, due to our rating. This really could blow some of the younger 13-15yr olds.

omg, im in 8th grader, heres the code:

onClipEvent (enterFrame) {
if (_x>300-_width/2) {
_x = 300-_width/2-1;
xv = xv*-0.9;
}
if (_x<0+_width/2) {
_x = 0+_width/2+1;
xv = xv*-0.9;
}
if (_y<0+_width/2) {
_y = 0+_width/2+1;
yv = yv*-0.9;
}
if (_y>300-_width/2) {
_y = 300-_width/2-.1;
yv = yv*-0.9;
}
if (!drag) {
xv = xv*.99;
yv = yv*.99 +.5;
_x = _x += xv;
_y = _y += yv;
} else {
xv = _x-x;
yv = _y-y;
x = _x;
y = _y;
}
}

Thats the best i can do (it should work)..

Ed Mack, come on man stop picking on the little kids (me)

xDrunkCowx
10-24-2002, 01:35 AM
Originally posted by mouse111
blow what?

how is it unsuitable

it may not be that great cause the bounces are not true bounces they just hit something and reverse direction at a constant speed, but how is it unsuitable

When something bounces off of a wall does it come back off the ball at the same speed as it hit the wall? no you instead of * the velocity by -1 multiply it by -0.9 that way it slows the ball down a little... making a more relistic script..

Ed Mack
10-29-2002, 10:00 AM
Originally posted by xDrunkCowx

Ed Mack, come on man stop picking on the little kids (me)

I think you completly missed the jokes.... they were with Bit101 mainly.

Anyway, I'm not quite sure of how the school system works in other countries, but I'm probably about the same age as you.

xDrunkCowx
10-29-2002, 07:06 PM
well im 14 and in 8th grader... i dont get what u ment by they are with bit101??

xDrunkCowx
10-29-2002, 07:11 PM
Originally posted by mouse111
ugh i understand now

its a pretty simplistic way of making a cheasy effect

o well

cool i guess.. but its wierd how when the ball starts moving at a slow speed it just stops... i take it ur using a if statment to do change the _x velocity?

Nionicle
10-30-2002, 12:57 AM
hey mr 8th grader.
I an 11th grader need help under standing your code.
Can you post the same code for me with an explanation of the different parts.


thanx bud

xDrunkCowx
10-30-2002, 08:33 AM
onClipEvent (enterFrame) {
// checking if the wall if hitting the right wall.. To find this out you take the _x - _width/2 and if that is greater than or equal to the _x of the wall then the ball is touching. _width/2 is the radius,
if (_x>300-_width/2) {
// if the ball is touching the wall then you move it back so its not touching the ball. Then the ball would just keep on hitting that one wall then mving back and doing this for ever. So now we need to change the xv, the angel a object hits a wall is the same angel the object leaves the wall but reversd. For example if the ball xv is 5 when it hits the wall then it needs to be changed to -5. to do that we would just take the xv and multiply it by -1 so if its a positive number then it turns into a negitive number and if its a negitive number then it turns into a positive number. But when a object hits a wall (remember we are doing elastic collision so the ball bounces) it looses speed so we multiply it by -0.9 so if the xv is 2 then now its -1.8.
_x = 300-_width/2-1;
xv = xv*-0.9;
}
if (_x<0+_width/2) {
_x = 0+_width/2+1;
xv = xv*-0.9;
}
if (_y<0+_width/2) {
_y = 0+_width/2+1;
yv = yv*-0.9;
}
if (_y>300-_width/2) {
_y = 300-_width/2-.1;
yv = yv*-0.9;
}
// now that we have checked to see if the ball is hitting any of the walls, and if it is we change the velocitie. Now what about gravity and friction? Well to add friction just multiply the xv and yv by .99 couse .99 makes the most relistic friction. Then to add gravity just add .5 to the yv so that way no matter what the bal is going to want to move downword.
// if the ball is not being draged then the script calculates friction and gravity and then moves the ball(as seen above).
if (!drag) {
xv = xv*.99;
yv = yv*.99 +.5;
_x = _x += xv;
_y = _y += yv;
} else {
// if the user is dragging the ball then we need to find the throwing power, so you take the oldx and y and subtract it from the new x and y and the distance between is the new xv and yv.
xv = _x-x;
yv = _y-y;
x = _x;
y = _y;
}
}
Now just open the circle mc and make the circle a button and put:
on (press) {
startDrag (this);
drag = true;
}
on (release, releaseOutside) {
stopDrag ();
drag = false;
}

This is from a tut i wrote earlyer on my site http://xdrunkcowx.tripod.com/ other tuts thier to..
i know thier are errors on the tut BUT im doing this with my time for free so as long as u can understand it... dont tell me about spelling or grammer errors

Nionicle
10-30-2002, 10:29 PM
Originally posted by xDrunkCowx
dont tell me about spelling or grammer errors

You misspelled grammar.

bit-101
10-31-2002, 11:49 PM
Originally posted by xDrunkCowx
well im 14 and in 8th grader... i dont get what u ment by they are with bit101??

it's just that the original post came off like he was presenting some amazing new discovery. but it is stuff that has probably been posted here and other boards a thousand times in the last few years. no big deal, just poking a little fun.

Ed Mack
11-01-2002, 02:07 PM
As Bit said, we were just having a bit of banter.

xDrunkCowx, I'm the same age as you.

I've attached a slightly fixed version of the posted code

xDrunkCowx
11-01-2002, 04:13 PM
not bad Ed Mack, and its nice to see people my age with that kind of talent.. i cant wait till people like u and me become 20+.. Flash is going to change a lot..

Ed Mack
11-02-2002, 09:59 AM
Nah, I'll probably have went mad by then and jumped off a bridge

xDrunkCowx
11-02-2002, 12:13 PM
ed mack why isnt ur site working?