Be a Supporter!

AS: Ball inertia

  • 2,556 Views
  • 28 Replies
New Topic Respond to this Topic
pivot11
pivot11
  • Member since: Jun. 16, 2006
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
AS: Ball inertia Mar. 25th, 2007 @ 08:09 PM Reply

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
EvanHayes
EvanHayes
  • Member since: Jan. 13, 2007
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to AS: Ball inertia Mar. 25th, 2007 @ 08:25 PM Reply

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.

pivot11
pivot11
  • Member since: Jun. 16, 2006
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to AS: Ball inertia Mar. 25th, 2007 @ 08:35 PM Reply

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


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

BBS Signature
Pyromaniac
Pyromaniac
  • Member since: Jan. 14, 2005
  • Offline.
Forum Stats
Member
Level 18
Blank Slate
Response to AS: Ball inertia Mar. 25th, 2007 @ 08:48 PM Reply

You should EXPLAIN the code instead of saying copy and paste, thats what the As:Main topics are for.

pivot11
pivot11
  • Member since: Jun. 16, 2006
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to AS: Ball inertia Mar. 25th, 2007 @ 08:54 PM Reply

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
Nuggs
Nuggs
  • Member since: Dec. 17, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to AS: Ball inertia Mar. 25th, 2007 @ 08:59 PM Reply

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
Pyromaniac
Pyromaniac
  • Member since: Jan. 14, 2005
  • Offline.
Forum Stats
Member
Level 18
Blank Slate
Response to AS: Ball inertia Mar. 25th, 2007 @ 09:14 PM Reply

At 3/25/07 08:54 PM, pivot11 wrote:
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.

Line by line buddy. Hell if you want I'll explain if you don't understand what it does.

pivot11
pivot11
  • Member since: Jun. 16, 2006
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to AS: Ball inertia Mar. 25th, 2007 @ 09:14 PM Reply

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
EvanHayes
EvanHayes
  • Member since: Jan. 13, 2007
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to AS: Ball inertia Mar. 25th, 2007 @ 09:23 PM Reply

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.

Kart-Man
Kart-Man
  • Member since: Jan. 7, 2007
  • Offline.
Forum Stats
Member
Level 27
Blank Slate
Response to AS: Ball inertia Mar. 25th, 2007 @ 09:33 PM Reply

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
pivot11
pivot11
  • Member since: Jun. 16, 2006
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to AS: Ball inertia Mar. 25th, 2007 @ 09:39 PM Reply

Go to the topic swingy thingy.


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

BBS Signature
Pyromaniac
Pyromaniac
  • Member since: Jan. 14, 2005
  • Offline.
Forum Stats
Member
Level 18
Blank Slate
Response to AS: Ball inertia Mar. 25th, 2007 @ 09:40 PM Reply

What you should do then is
//
var p1:Number;
var p2:Number;
//

EvanHayes
EvanHayes
  • Member since: Jan. 13, 2007
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to AS: Ball inertia Mar. 25th, 2007 @ 09:44 PM Reply

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.

GeoKureli
GeoKureli
  • Member since: Apr. 1, 2003
  • Offline.
Forum Stats
Supporter
Level 19
Game Developer
Response to AS: Ball inertia Mar. 25th, 2007 @ 10:04 PM Reply

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

suppi
suppi
  • Member since: Jun. 29, 2003
  • Offline.
Forum Stats
Member
Level 07
Audiophile
Response to AS: Ball inertia Mar. 25th, 2007 @ 10:14 PM Reply

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

GeoKureli
GeoKureli
  • Member since: Apr. 1, 2003
  • Offline.
Forum Stats
Supporter
Level 19
Game Developer
Response to AS: Ball inertia Mar. 25th, 2007 @ 10:16 PM Reply

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
pivot11
pivot11
  • Member since: Jun. 16, 2006
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to AS: Ball inertia Mar. 25th, 2007 @ 10:19 PM Reply

lol, ok...


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

BBS Signature
pivot11
pivot11
  • Member since: Jun. 16, 2006
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to AS: Ball inertia Mar. 26th, 2007 @ 04:42 PM Reply

wow, no replies?


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

BBS Signature
Cybex
Cybex
  • Member since: Mar. 4, 2005
  • Offline.
Forum Stats
Member
Level 20
Blank Slate
Response to AS: Ball inertia Mar. 26th, 2007 @ 05:47 PM Reply

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.

EvanHayes
EvanHayes
  • Member since: Jan. 13, 2007
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to AS: Ball inertia Mar. 26th, 2007 @ 06:10 PM Reply

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.

pivot11
pivot11
  • Member since: Jun. 16, 2006
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to AS: Ball inertia Mar. 26th, 2007 @ 06:22 PM Reply

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
ToasterDemon
ToasterDemon
  • Member since: May. 15, 2005
  • Offline.
Forum Stats
Member
Level 16
Blank Slate
Response to AS: Ball inertia Apr. 5th, 2007 @ 08:29 PM Reply

Any idea of how to add maximum string length?

pivot11
pivot11
  • Member since: Jun. 16, 2006
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to AS: Ball inertia Apr. 5th, 2007 @ 08:30 PM Reply

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
Ansel
Ansel
  • Member since: Sep. 2, 2006
  • Offline.
Forum Stats
Member
Level 23
Blank Slate
Response to AS: Ball inertia Apr. 5th, 2007 @ 09:33 PM Reply

hmmm. how can i modify this so that the ball rotates to face the mouse at all times?


BBS Signature
LesPaulPlayer
LesPaulPlayer
  • Member since: May. 18, 2006
  • Offline.
Forum Stats
Member
Level 12
Blank Slate
Response to AS: Ball inertia Apr. 5th, 2007 @ 09:55 PM Reply

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.

EvanHayes
EvanHayes
  • Member since: Jan. 13, 2007
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to AS: Ball inertia Apr. 5th, 2007 @ 09:56 PM Reply

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.

ToasterDemon
ToasterDemon
  • Member since: May. 15, 2005
  • Offline.
Forum Stats
Member
Level 16
Blank Slate
Response to AS: Ball inertia Apr. 6th, 2007 @ 09:50 AM Reply

So nobody has any idea of the code that would give a max string length?

izzy032294
izzy032294
  • Member since: Feb. 2, 2008
  • Offline.
Forum Stats
Member
Level 02
Blank Slate
Response to AS: Ball inertia Feb. 2nd, 2008 @ 05:02 PM Reply

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

pivot11
pivot11
  • Member since: Jun. 16, 2006
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to AS: Ball inertia Mar. 26th, 2008 @ 10:35 AM Reply

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