00:00
00:00
Newgrounds Background Image Theme

Jesspionic just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

AS: Ball inertia

3,476 Views | 22 Replies
New Topic Respond to this Topic

AS: Ball inertia 2007-03-25 20:09:52


AS: main

INTRO: First off, I got this from the topic "swingy thingy". Thanks to sk8more, this can be done.

WHAT: Well, this concept is like a rubber band. When you move your mouse the ball slings itself at the direction to move it to. The strind is connected to the ball, and the string is the thing that acts like a rubberband.

WHY: You can use this in multible ways. I'm using this to make a game. It'll come out soon.

Example: here

Tutorial:

First, make a ball. This ball can be anything you want it to be, because this is what is being "bungied". Press F8. Make it a movieclip and name it "ball". Now, go to the properties and give it an instance name of "ball". No quotes.

Press F9 and copy this code in:

onClipEvent (load) {
inertia =.9;
ki = 0.1;
x1 =33
y1 =33
}
onClipEvent (enterFrame) {
x = -_x+_root._xmouse;
y = -_y+_root._ymouse;
x1 = x1*inertia+x*ki;
y1 = y1*inertia+y*ki;
_x += x1;
_y += y1;

}

This code is simply giving it it's physical properties. The mouse moves, the ball moves at a faster pace. When it's at it's max length, it slows down. Then, comes back. This gives it a rubber band characteristic.

Now on the very frame where you have that ball, put this code in: (hint: highlight the frame)

onEnterFrame=function () {
with (createEmptyMovieClip("line", 1)) {
lineStyle(10)
moveTo(_root._xmouse,_root._ymouse)
lineTo(ball._x,ball._y)
}
}

This is the rubber band. This code says that where ever the bale ball is that side stays with the ball. And the other side follows the mouse.

I hoped this helped you. I tried to explain what the codes briefly. You get the idea.

-pivot (AKA: msmstudios)


Blok' Party, Orbital Khaos, site, MSMstudios, Phrozen Phlame

BBS Signature

Response to AS: Ball inertia 2007-03-25 20:25:41


hahah nice pivot,woo im in an as main topic :)
ill bookmark it even though...
well it has my name in it,but good tut


Grah i feel so unknown, SK8MORE god damn :/ EvanHayes seems like a much more serious name than sk8more,so i changed it.

Response to AS: Ball inertia 2007-03-25 20:35:18


I hope this gets added to As: main...


Blok' Party, Orbital Khaos, site, MSMstudios, Phrozen Phlame

BBS Signature

Response to AS: Ball inertia 2007-03-25 20:54:07


At 3/25/07 08:48 PM, Pyromaniac wrote: You should EXPLAIN the code instead of saying copy and paste, thats what the As:Main topics are for.

I did. I explained what it does and why.


Blok' Party, Orbital Khaos, site, MSMstudios, Phrozen Phlame

BBS Signature

Response to AS: Ball inertia 2007-03-25 20:59:33


How did you decide to set the variables at such seemingly random numbers?
inertia =.9;
ki = 0.1;
x1 =33
y1 =33


Games|1|2|3| Movies|1|2|

BBS Signature

Response to AS: Ball inertia 2007-03-25 21:14:26


At 3/25/07 08:59 PM, Nuggs wrote: How did you decide to set the variables at such seemingly random numbers?
inertia =.9;
ki = 0.1;
x1 =33
y1 =33

Random, and then he tested to see if it was good or not...


Blok' Party, Orbital Khaos, site, MSMstudios, Phrozen Phlame

BBS Signature

Response to AS: Ball inertia 2007-03-25 21:23:19


ok,well inertia is how long the ball moves and kinetik(k) its how fast or how much kenetic energy there is the higher the number k is the faster and same with enertia but it increases distance

p1x and p1y are random set them to whatever,you just need a variable to be defined as a number


Grah i feel so unknown, SK8MORE god damn :/ EvanHayes seems like a much more serious name than sk8more,so i changed it.

Response to AS: Ball inertia 2007-03-25 21:33:05


At 3/25/07 09:23 PM, sk8more wrote: explanation

Shouldn't sk8more have made this thread, as it's his code?

Oh whatever; regardless, it's an interesting effect.

postcount +=1;

Newgrounds Photoshop Headquarters || Don't use MS Paint! Use Aviary!

SING US A SING YOU'RE THE PIANO MAN

BBS Signature

Response to AS: Ball inertia 2007-03-25 21:39:48


Go to the topic swingy thingy.


Blok' Party, Orbital Khaos, site, MSMstudios, Phrozen Phlame

BBS Signature

Response to AS: Ball inertia 2007-03-25 21:44:47


yea,that is more efficient,but for most people that way works just as well,just a bit more laggy if you have like 300 of them but for now its fine


Grah i feel so unknown, SK8MORE god damn :/ EvanHayes seems like a much more serious name than sk8more,so i changed it.

Response to AS: Ball inertia 2007-03-25 22:04:12


this isnt a tutorial. its a code snippet. they wont learn anything

Response to AS: Ball inertia 2007-03-25 22:14:32


who cares yo most people that need these tutorials dont have the mental capacity to learn these codes - like me!

Response to AS: Ball inertia 2007-03-25 22:16:44


At 3/25/07 10:14 PM, suppi wrote: who cares yo most people that need these tutorials dont have the mental capacity to learn these codes - like me!

oh that makes total sense

im outta here

Response to AS: Ball inertia 2007-03-25 22:19:42


lol, ok...


Blok' Party, Orbital Khaos, site, MSMstudios, Phrozen Phlame

BBS Signature

Response to AS: Ball inertia 2007-03-26 16:42:46


wow, no replies?


Blok' Party, Orbital Khaos, site, MSMstudios, Phrozen Phlame

BBS Signature

Response to AS: Ball inertia 2007-03-26 17:47:55


At 3/25/07 08:54 PM, pivot11 wrote: I did. I explained what it does and why.

Not really, you even suggested they should just copy and paste the code. You explained wehat the code does breifly, but you didn't say why it does that and exactl how. You want to explain it so that someone with AS knowledge could reproduce it with only the explanation.

Response to AS: Ball inertia 2007-03-26 18:10:19


do you think i should remake this tut?
considering its my code.


Grah i feel so unknown, SK8MORE god damn :/ EvanHayes seems like a much more serious name than sk8more,so i changed it.

Response to AS: Ball inertia 2007-03-26 18:22:59


Awwww, but I always tried to make an AS thing but all the topics were taken.


Blok' Party, Orbital Khaos, site, MSMstudios, Phrozen Phlame

BBS Signature

Response to AS: Ball inertia 2007-04-05 20:30:56


How did this get out!!! And yes, the intervals. mess with those. Or just ask sk8more


Blok' Party, Orbital Khaos, site, MSMstudios, Phrozen Phlame

BBS Signature

Response to AS: Ball inertia 2007-04-05 21:55:06


At 4/5/07 09:33 PM, JunkyCow wrote: hmmm. how can i modify this so that the ball rotates to face the mouse at all times?

wow. I dont even know how you don't know this. Thats like some of the most important AS ever.

Response to AS: Ball inertia 2007-04-05 21:56:35


At 4/5/07 09:33 PM, JunkyCow wrote: hmmm. how can i modify this so that the ball rotates to face the mouse at all times?

ok,junky you have to use a atan2 function
x=_x-_root._xmouse
y=_y-_root._ymouse
_rotation=Math.atan2(y,x)/(Math.PI/180)

in an onClipEvent handler and you got yourself some rotation

woot,go my code :)


Grah i feel so unknown, SK8MORE god damn :/ EvanHayes seems like a much more serious name than sk8more,so i changed it.

Response to AS: Ball inertia 2008-02-02 17:02:30


ok I'll try to figure this out

onClipEvent (load) { //this just loads variables
inertia =.9; //these are the variables
ki = 0.1;
x1 =33;
y1 =33;
}

onClipEvent (enterFrame) { //basically means at all times

x = -_x+_root._xmouse; //the x is the balls x coordinates plus the mouse's x coordinates
y = -_y+_root._ymouse; // the y is the balls y coordinates plus the mouse's y coordinates

x1 = x1*inertia+x*ki; //the x1 is itself times inertia(making itself less and less)+x(we explained above what x was) times ki making it less and less
y1 = y1*inertia+y*ki; //the y1 is itself times inertia(making itself less and less)+y(we explained above what y was) times ki (making it less and less)

the part that makes everything work is coming up

_x += x1; // which means the ball x position is x1 which always gets less and less until it hits zero I didn't say that above because what is .9(inertia) times 0?
_y += y1; // which means the ball y position is y1 which always gets less and less until it hits zero.
once they both hit zero the ball stops until you move the mouse then the ball takes it's x and y position subtracted from the mouse's x and y and multiplied by inertia

I hope I helped and didn't just confuse people more

Response to AS: Ball inertia 2008-03-26 10:35:21


At 2/2/08 05:02 PM, izzy032294 wrote: ok I'll try to figure this out

onClipEvent (load) { //this just loads variables
inertia =.9; //these are the variables
ki = 0.1;
x1 =33;
y1 =33;
}

onClipEvent (enterFrame) { //basically means at all times

x = -_x+_root._xmouse; //the x is the balls x coordinates plus the mouse's x coordinates
y = -_y+_root._ymouse; // the y is the balls y coordinates plus the mouse's y coordinates

x1 = x1*inertia+x*ki; //the x1 is itself times inertia(making itself less and less)+x(we explained above what x was) times ki making it less and less
y1 = y1*inertia+y*ki; //the y1 is itself times inertia(making itself less and less)+y(we explained above what y was) times ki (making it less and less)

the part that makes everything work is coming up

_x += x1; // which means the ball x position is x1 which always gets less and less until it hits zero I didn't say that above because what is .9(inertia) times 0?
_y += y1; // which means the ball y position is y1 which always gets less and less until it hits zero.
once they both hit zero the ball stops until you move the mouse then the ball takes it's x and y position subtracted from the mouse's x and y and multiplied by inertia

I hope I helped and didn't just confuse people more

Oh, inertia is how stretchy it can go. If you set it to 1 itll never come back to the ball. .99 is the most elastic, and .00001 (etc to infinity) is the least. I set it to .9 as it was comfortable to me. If you want it to stratch more put .95. Less, put like .70


Blok' Party, Orbital Khaos, site, MSMstudios, Phrozen Phlame

BBS Signature