Please Help Me Get This Actionscript Ball Rolling
I am just starting w/ actionscript, and I am following O'Reilly's guide. I entered my first few lines of actionscript to the T. I am not a Flash idiot, but am no expert. I tested the movie: checked, and re-checked about 30X's, and it outputs nothing, does anyone have experience with this sort of thing?
The code I entered is as follows:
var message = "Hi there, Flash!"; var firstName = "Giuseppe"; trace (message); trace ("Hi there, " + firstName + ", nice to meet you.");
I open the output window, press test and nothing happens.
FlashKit > Flash Help > Flash ActionScript
Posted on: 06-25-2003, 10:39 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Please Help Me Get This Actionscript Ball Rolling
I am just starting w/ actionscript, and I am following O'Reilly's guide. I entered my first few lines of actionscript to the T. I am not a Flash idiot, but am no expert. I tested the movie: checked, and re-checked about 30X's, and it outputs nothing, does anyone have experience with this sort of thing?
The code I entered is as follows:
var message = "Hi there, Flash!";
var firstName = "Giuseppe";
trace (message);
trace ("Hi there, " + firstName + ", nice to meet you.");
I open the output window, press test and nothing happens.
Rolling Ball
I want to make a photo of a tennis ball roll along the the screen before coming to a halt. I have made the bitmap into a movie clip symbol (F8) and have used pi x D to calculate the circumferance and using that calculated the length of the tween and number of rotations required.
The problem is that the origin for the rotate in the tween has defaulted to the top left of the movie clip symbol and I can't figure out how to move the origin to the centre.
Can anyone help?
Many thanks
Ralph
Rolling Ball...
Hi,
I am using the following 2 lines of code to control the timeline inside the about us page of this website i am building.
on (release) {
if (this._parent._currentframe == this._parent._totalframes) {
this._parent.gotoAndStop(5);
} else {
this._parent.nextFrame();
}
}
and
on (release) {
if (this._parent._currentframe == 5) {
this._parent.gotoAndStop(this._parent._totalframes );
} else {
this._parent.prevFrame();
}
}
I would like to make the prev/next ball to roll from one position to the next, but i just cant work it out.
I would be enternally grateful if one of you actionscript guru's could help me.
Thanks in advance,
Julian
Rolling Ball
Hi,
Try to find a solution for a problem I'm fighting with.
I have a ball in 3d shape with a strukture on it. This I want to roll over the stage in any direction but the structure has to roll with and thats not so easy . But anyway if somebody got ideas. please let me know.
Thank you
Michael
Ball Rolling Instead Of Sliding?
If I have a billiard ball (a stripe ball) going from point A (0, 0) to point B (5, 15). Is there a way to animate it so that the ball is rolling from point A to B with the stripe spinning along with it?
What about angle, the change of velocity... how do I animate the spinning stripe?
I could create a spinning stripe in Swift. But am I supposed to create 180 versions of spinning stripe so that I could apply it through the 360 degree of angle the ball's going?
Or should I create 2 arcs with Flash, and then the next frame delete the 2 arcs and create 2 arcs with a new angle, and the next frame delete'em... etc.. but wouldn't it be extemely slow for 9 stipe billiard balls?
Any help is greatly appreciated.
Rolling Ball Effect In AS3.0
Tutorial here: http://www.emanueleferonato.com/2007...s-and-masking/
Now I want to do this in AS3.0, but the problem is I don't even know how to apply a texture to an object, because the texture method (seen in AS2.0) seems to be removed. Any help?
[F8] Ball Rolling Along A Line.
Hi everyone.
I would like to ask anyone of you who have resources for a very simple line rider concept. Emmanuel Feronato's tutorial is just too much for me and it is not exactly what I need.
Here's the idea: A simple slanted platform (like a simple line) and a ball that detects it and rolls down along the slanted path via a gravity variable.
It continues to fall to the ground once it reaches the end of that line.
That's it. Many thanks to those who can help. I hope you have an idea what I'm trying to get to.
Ball Rolling On A Curve?
Hi I see this is probably complicated but I wanted to see if there was code or a tutorial somewhere I can grab.
I am trying to figure out how to have a ball drop onto a Curved line. (Shaped like a "U" (2d). And have the ball roll down the side and go to the middle.
I found a great example similar but on a flat line here:
http://www.actionscript.org/forums/s...ight=ball+roll
Are there any other examples that do what I am saying? I attatched an example of I am saying except I just have the ball fall through the line, but I want it to roll down the line.
Thanks for the help
Ball Won't Stop Rolling....
In a game I'm making, a physics-based game, I need a ball to be able to bounce, and roll around.
I've worked out everything in the behaviour of the ball, except for the slowing of the ball's sideways movement. It slows down to a near stop, but then speeds up and starts bouncing off the wall to left.
I used a very simple script to slow the ball. It's horizontal speed is xSpeed, here's the script:
ActionScript Code:
slow = 0.9;
xSpeed *= slow;
_x += xSpeed;
I figured that would be an easy way to slow it down, but the ball won't stop unless I use an unrealistic variable to slow it, where it stops almost immediately after it began moving.
Any suggestions on how to fix this?
Sean
Rolling Ball Physics
Hi all,
I need some help...
I am trying to design a flash sequence where a ball starts rolling, then slows down.
What is the easiest and most effective way to show a ball going from full speed to a gradual stop?
Thank you.
Ball Rolling Instead Of Sliding?
If I have a billiard ball (a stripe ball) going from point A (0, 0) to point B (5, 15). Is there a way to animate it so that the ball is rolling from point A to B with the stripe spinning along with it?
What about angle, the change of velocity... how do I animate the spinning stripe?
I could create a spinning stripe in Swift. But am I supposed to create 180 versions of spinning stripe so that I could apply it through the 360 degree of angle the ball's going?
Or should I create 2 arcs with Flash, and then the next frame delete the 2 arcs and create 2 arcs with a new angle, and the next frame delete'em... etc.. but wouldn't it be extemely slow for 9 stipe billiard balls?
Any help is greatly appreciated.
Rain Falling On The Ball And Rolling Down Randomly
hi everyone,
i need help in the concept where the rain falls(object with duplicate mc's) on the circular shape (ball). As the raindrop touches the ball raindrop should rolldown with natural effect. something like raindrops falling on the ball and rolling down smoothly and randomly. Please anyone help me in this regard.....
Thanks in Advance
Ball Vs. Ball Collisions: Un-penetrating The Ball
Hello
I have been reading tonypa's vector tutorials(http://www.tonypa.pri.ee/vectors/tut09.html), and I came across a special case that I am not sure how to deal with.
Suppose I have a ball bouncing around inside of a larger ball (I will call it the wheel). Now I know how to tell when the ball moves out of the wheel, and how I am supposed to move it back in (at least according to tonypa: var penetration=wheel.r-(ball.r+v.len) )
What I understand this does is it moves the ball back inside of the other ball along the line defined between the center of the ball and the center of the wheel.
However, wouldn't this be inaccurate? Shouldn't the ball be moved back along the line of the ball's original direction?
If so, how would I calculate the amount to move it back in?
Thanks in advance for your help.
Sorry if my post is confusing
[FMX] HELP Bouncing Ball Using Actionscript
hey,
I haven't done much actionscript stuff ...and at the moment im trying to make a ball bounce across the stage, but im unsure how to go about doing that....any help would be much appreciated.
thanks
katey aka "actionscript dummy"
[FMX] HELP Bouncing Ball Using Actionscript
hey,
I haven't done much actionscript stuff ...and at the moment im trying to make a ball bounce across the stage, but im unsure how to go about doing that....any help would be much appreciated.
thanks
katey aka "actionscript dummy"
Rotating A Ball By Actionscript..
Hi guys,
Can you please help me..
I need an actionscript that can rotate a small ball around another Mc. I do not want to use the _rotate function, because then I won't be able to place the ball in centre of it's Mc.
Thanks in advance.
Rotating A Ball In 3d With A Logo On It Using Actionscript.
Hi everyone,
Okay - I think this is a bit of a tough one.
I'm developing a 3d game involving a ball. The client wants their logo on the ball, so when the ball rotates, it needs to appear as if the logo rotates with it (ie: as if the logo is printed on the ball).
The ball is going to be bouncing off all kinds of surfaces and going all over the place, so I can't just create a 3d model and export a load of rotated images as I'd end up with a ridiculous amount of images.
So, where I am so far is....
I have a ball, with the logo on it, and a mask around it so that if I move the logo up or down it appears to disappear of the edge of the ball (as it would). By altering the _xscale and _yscale of the logo I also increase the realism of the logo disappearing round the side of the ball.
But, then I'm stuck. It looks great if the ball is rolling "away" from you but then as soon as it hits an angles surface and bounces off, the sideways rotation comes into play too and then I'm stuck.
I'm presuming there is a way to do this reasonably realistically. I know the x and y increase of my ball at any one time, and based on that I can obviously calculate the angle at which the ball is travelling.
Am I trying to do the impossible here or does anyone know whether there are any examples out there etc...?
Thanks in advance for any help.
Cheers.
Ian
Actionscript With Ball Rotate (help) Urgen
can someone help me in flash actionscript?
how to make a ball rotate in flash actionscrip and it can stop rotating by press mouse. the ball will stay on same position, it just rotates follow the mouse direction.
if you cant get the concept, there is an example which is using javascript to create it. please click on this link to refer http://nanoatlas.ifs.hr/index_2.html please help. i am really appriciate your help.
Simple Pool Cue Hitting Ball - How To Get Direction For Ball To Head?
Hey guys. First post here.
I'm just learning how to program in ActionScript. What I'm trying to do is have a pool cue hit a ball, and based on the direction the pool cue is facing, the ball needs to go in that direction. I've got it set up using hitTest() so that if the mouse position (mouse position is the end to the cue) is touching the ball and "s" key is pressed, the ball is hit. But from here I don't know how to get the direction for the ball to go, or how to get it to start moving. Any guidance would be really appreciated. Thanks.
Advice Requested: Actionscript Concepts In Creating Ball Game
Greetings Flash-fiends,
I would appreciate a few words of advice before I embark on a considerable personal project.
I would like to simulate a ball game using a technique similar to the wonderful Conversion Kings (http://www.sportal.co.za/).
However, whilst I'm an ok programmer, and a good animator / artist, the mathematics side of this is really going to test me (yes, I was the guy who sat at the back of maths class drawing the teachers. Kids - I wish I had paid attention instead).
What I was hoping for from you guys is some kind of direction as to the mathematical factors I may have to consider, in creating something similar to Wireframes masterpiece, from scratch.
For example, my ball will need to be told its Xpos and Xpos, and I will have to simulate a Zpos to give the illustion of size. The Zpos will be largely dependent on a Power variable (ie how hard the ball has been struck). However, the Zpos (size / scale) reduction will need to slow down over time to create the appearance of perspective. Also, my ball needs to curve in the air (both through spin AND gravity). Does this mean a parabola?
Whew. I sat down last night with a pen and a paper, and realised how much thought this needs. Any assistance (in simplified language) would be a great help.
Many, many thanks in advance,
Lewis Boadle
http://www.boadle.com
Ball Hitting Mouse Causes Ball To Go The Opposite Direction.
Here is my poor attempt to get into some scripting. I would like the ball to go the opposite direction if my mouse hits it.
I have a ball called ballmv.
I put this script on the ballmv:
Code:
onClipEvent(load){
speed = 10;
}
// this causes my ball to bounce off the walls
onClipEvent(enterFrame){
this._x = this._x + speed;
if(this._x >= _root.wallPos -53 || this._x <= _root.wallPos2 +53){
speed = -speed;
}
}
// this is for the mouse to deflect the ball
onClipEvent(enterFrame){
var xMouse = _root._xmouse;
if(xMouse.hitTest(_root.ballmv)){
with(_root.ballmv){
speed = -speed;
}
}
}
Also, am I writing my coding the long way? How should I write this. The mouse ball deflect thing doesn't work though but the others do.
Setting A Variable: Var Ball Or Ball?
Hi,
I might be asking a stupid question so please excuse me.
What's the difference between the below and when should I use which?
Code:
ball=50;
and
Code:
var ball=50;
Thanks
Line From One Ball To Another Draggable Ball.
http://www.geocities.com/nmgwebsite/thing.swf
You will need to Copy and paste the url.
code:
onClipEvent (load) {
startDrag("_root.ball", true);
}
onClipEvent (enterFrame) {
x = _root.ball._x-_root.ball2._x;
y = _root.ball._y-_root.ball2._y;
radians = Math.atan2(y, x);
degrees = radians/(Math.PI/180);
_root.bar._rotation = degrees;
distance = Math.sqrt(x*x+y*y);
_root.bar._xscale = distance/1.78;
}
That just does not look right. Does anybody know what I am doing wrong? Thanks!
Ball Vs Ball Collision Revisited
Ok, before I get flamed, I know there are tons of posts dealing with ball vs ball collision and I have looked over any I could find on the forum, however none of them seem to work exactly like I want and I have been looking over examples for weeks now.
I have a script I modified from jbum's example (http://board.flashkit.com/board/show...hreadid=538918) that is pretty close but there is one problem I have yet to solve. Here is my modified code:
This part just updates the balls position based on their vx and vy variables. It gets called on a timer:
code:
public function moveBalls():void {
var loopLength=ballArray.length-1;
for (var count:int=0; count<=loopLength; count++) {
var currentBall=ballArray[count];
var currentBallRadius=currentBall.ballRadius;
currentBall.tempX = currentBall.x;
currentBall.tempY = currentBall.y;
currentBall.tempX += currentBall.vx;
currentBall.tempY += currentBall.vy;
if (currentBall.tempY-currentBallRadius<topEdge) {
currentBall.tempY = topEdge+currentBallRadius;
currentBall.vy *= -1;
}
else if (currentBall.tempY+currentBallRadius>bottomEdge) {
currentBall.tempY = bottomEdge-currentBallRadius;
currentBall.vy *= -1;
}
if (currentBall.tempX-currentBallRadius<leftEdge) {
currentBall.tempX = leftEdge+currentBallRadius;
currentBall.vx *= -1;
}
else if (currentBall.tempX+currentBallRadius>rightEdge) {
currentBall.tempX = rightEdge-currentBallRadius;
currentBall.vx *= -1;
}
}
for (count=0; count<=loopLength; count++) {
currentBall=ballArray[count];
for (var subCount:int=count+1; subCount<=loopLength; subCount++) {
var currentSubBall=ballArray[subCount];
var xdiff:Number = currentSubBall.tempX-currentBall.tempX;
var ydiff:Number = currentSubBall.tempY-currentBall.tempY;
var dist:Number = Math.sqrt(xdiff*xdiff+ydiff*ydiff);
if ((dist<=(currentBallRadius+currentSubBall.ballRadi us)) && (!currentBall.isCollide ||!currentSubBall.isCollide) ) {
currentBall.isCollide=true;
currentSubBall.isCollide=true;
doCollisionNew(currentBall,currentSubBall,dist,xdi ff,ydiff);
}
else {
currentBall.isCollide=false;
currentSubBall.isCollide=false;
}
}
}
updateBalls();
}
Next we actually update the balls real position:
code:
function updateBalls():void {
var loopLength=ballArray.length-1;
for (var count:int=0; count<=loopLength; count++) {
var currentBall=ballArray[count];
currentBall.x = currentBall.tempX;
currentBall.y = currentBall.tempY;
}
}
Ok, and here is the real part I'm having problems with. It gets called when there is a collision:
code:
function doCollisionNew(b1:BreakerBall, b2:BreakerBall,dist,xdiff,ydiff):void {
var mag1 = Math.sqrt(b1.vx*b1.vx+b1.vy*b1.vy);
var mag2 = Math.sqrt(b2.vx*b2.vx+b2.vy*b2.vy);
if ( dist==0) {
var angle = Math.atan2(ydiff,xdiff);
var cosa = Math.cos(angle);
var sina = Math.sin(angle);
var diff = ((b1.ballRadius+b2.ballRadius)-dist)/2;
var cosd = cosa*diff;
var sind = sina*diff;
b1.tempX -= cosd;
b1.tempY -= sind;
b2.tempX += cosd;
b2.tempY += sind;
b2.vx=-b1.vx;
b2.vy=-b1.vy;
b1.vx=-b2.vx;
b1.vy=-b2.vy;
}
else {
b2.vx = (mag1*xdiff/dist);
b1.vx = -(mag2*xdiff/dist);
b2.vy = (mag1*ydiff/dist);
b1.vy = -(mag2*ydiff/dist);
}
}
Most of it is the same as jbum's script except I added the part within the if statement ( if (dist==0) {....} ). This is kind of a hack, because I found if the balls are moving fast enough where they end up on top of each other, the vx/vy comes back as NaN and the balls end up stuck in the top left corner of the screen. Probably not the "right" way to do things, but it seems to work ok for my purposes.
Alright, so what I'm looking for is a random number of balls bouncing around the screen and colliding against each other in the simplest way possible. Everything works fine with this code, however if two balls start at the same Y position and travel down and toward each other, they collide wrong. Instead of moving outward from each other and continuing down, instead they just get stuck bouncing back and forth straight on x. Here is an example of this where ball1 starts at x=30, y=50 and ball2 starts at x=230, y=50. The first ball has vx=5, vy=5 and the second ball is vx=-5, vy=5.
http://metalblend.com/ballTest/proto-2a.html
This should work more like this:
http://metalblend.com/ballTest/proto-2b.html
The problem I see is that if the first balls vy is equal to the second balls vy then the variable ydiff is equal to zero. This causes this
code:
b2.vy = (mag1*ydiff/dist);
b1.vy = -(mag2*ydiff/dist);
to set both balls vy to zero, making them 'stuck' on the x plane.
I can get it to work right (shown in the second link) using this script for the collision calculation instead:
code:
function doCollision(b1:BreakerBall, b2:BreakerBall, dist:Number, xdiff:Number, ydiff:Number):void {
var angle = Math.atan2(ydiff,xdiff);
var cosa = Math.cos(angle);
var sina = Math.sin(angle);
var vx1p = cosa*b1.vx+sina*b1.vy;
var vy1p = cosa*b1.vy-sina*b1.vx;
var vx2p = cosa*b2.vx+sina*b2.vy;
var vy2p = cosa*b2.vy-sina*b2.vx;
var P = vx1p+vx2p;
var V = vx1p-vx2p;
vx1p = (P-V)/2;
vx2p = V+vx1p;
b1.vx = cosa*vx1p-sina*vy1p;
b1.vy = cosa*vy1p+sina*vx1p;
b2.vx = cosa*vx2p-sina*vy2p;
b2.vy = cosa*vy2p+sina*vx2p;
var diff = ((b1.ballRadius+b2.ballRadius)-dist)/2;
var cosd = cosa*diff;
var sind = sina*diff;
b1.tempX -= cosd;
b1.tempY -= sind;
b2.tempX += cosd;
b2.tempY += sind;
}
There are a couple problems with using the second script though. One of the main problems, is that I would like all the balls to stay at a constant speed after they collide. This is probably more of a "fake" collision, but that is what I am looking for. With this second function if you start all balls out with the same speed like vx=5,vy=5 for all balls, after bouncing for a bit, some start to move slower and some start to move faster.
Here is an example of this problem (using the more complex script):
http://metalblend.com/ballTest/proto-2c.html
The first script (jbum's) doesn't do this (they stay at a constant speed):
http://metalblend.com/ballTest/proto-2d.html
Also this second function has much more calculations to it and I'd rather keep it simple to avoid overhead and frame rate problems when dealing with a lot of balls bouncing. As well, this script is too confusing for me to understand for the most part .
So...if anyone knows an easy way to make the first script work right, without the problem of getting stuck on the x plane, MUCH APPRECIATED .
Oh,and the source file's I'm playing with can be downloaded here:
http://metalblend.com/ballTest/ballTest.zip
Ball Game (ball Goes Through Boundaries)
I have a ball game where the ball is suppesed to bounce off of the boundaries to get to the finish (the player draws a set of boundaries and then lets the ball fall and see if it makes it to the finish). It usually works but sometimes the ball goes through the boundaries. It is really bad when i have moving terrain because if the ball is going the opposite dirrection than the terrain it usually goes right through it. Also, I don't know if this can be fixed but sometimes the ball gets inside a line making up the terrain and starts bouncing around inside of the line. I have tried everything from increasing the frame rate to changing the variable values. please help.
heres the code for the ball ( sorry it's so long it repeats once so that the ball bounces off the players terrain as well as the premade terrain):
PHP Code:
onClipEvent (load) {
yspeed = 0;
xspeed = 0;
gravity = 0.2;
radius = 5;
friction = 0.90;
precision = 420;
bounces = 0;
}
onClipEvent (enterFrame) {
if (_root.go == true) {
collisions = 0;
sum_x = 0;
sum_y = 0;
yspeed = yspeed+gravity;
for (x=1; x<precision; x++) {
spot_x = _x+radius*Math.sin(x*360/precision);
spot_y = _y-radius*Math.cos(x*360/precision);
if (_root.terrain.hitTest(spot_x, spot_y, true)) {
collisions++;
sum_x += spot_x;
sum_y += spot_y;
}
}
if (collisions>0) {
_root.last_hit._x = old_x;
_root.last_hit._y = old_y;
bounces++;
_root.collisions.text = "Bounces: "+bounces;
ball_dir = Math.atan(yspeed/(xspeed*-1))/(Math.PI/180);
if ((xspeed*-1)<0) {
ball_dir += 180;
}
if ((xspeed*-1)>=0 && yspeed<0) {
ball_dir += 360;
}
spot_x = sum_x/collisions;
spot_y = sum_y/collisions;
x_cat = spot_x-_x;
y_cat = spot_y-_y;
ball_coll = Math.atan(y_cat/x_cat)/(Math.PI/180);
if (x_cat<0) {
ball_coll += 180;
}
if (x_cat>=0 && y_cat<0) {
ball_coll += 360;
}
ground_rotation = ball_coll-90;
if (ground_rotation<0) {
ground_rotation += 180;
}
bounce_angle = 180-ball_dir-2*(ground_rotation);
if (bounce_angle<0) {
bounce_angle += 360;
}
speed = Math.sqrt((yspeed*yspeed)+(xspeed*xspeed));
xspeed = speed*Math.cos(bounce_angle*Math.PI/180)*friction;
yspeed = (speed*Math.sin(bounce_angle*Math.PI/180))*-1*friction;
_x = old_x;
_y = old_y;
}
else{
old_x = _x;
old_y = _y;
}
_y = _y+yspeed;
_x = _x+xspeed;
}
}
onClipEvent (enterFrame) {
if (_root.go == true) {
collisions = 0;
sum_x = 0;
sum_y = 0;
yspeed = yspeed+gravity;
for (x=1; x<precision; x++) {
spot_x = _x+radius*Math.sin(x*360/precision);
spot_y = _y-radius*Math.cos(x*360/precision);
if (_root.terrain2.hitTest(spot_x, spot_y, true)) {
collisions++;
sum_x += spot_x;
sum_y += spot_y;
}
}
if (collisions>0) {
_root.last_hit._x = old_x;
_root.last_hit._y = old_y;
bounces++;
_root.collisions.text = "Bounces: "+bounces;
ball_dir = Math.atan(yspeed/(xspeed*-1))/(Math.PI/180);
if ((xspeed*-1)<0) {
ball_dir += 180;
}
if ((xspeed*-1)>=0 && yspeed<0) {
ball_dir += 360;
}
spot_x = sum_x/collisions;
spot_y = sum_y/collisions;
x_cat = spot_x-_x;
y_cat = spot_y-_y;
ball_coll = Math.atan(y_cat/x_cat)/(Math.PI/180);
if (x_cat<0) {
ball_coll += 180;
}
if (x_cat>=0 && y_cat<0) {
ball_coll += 360;
}
ground_rotation = ball_coll-90;
if (ground_rotation<0) {
ground_rotation += 180;
}
bounce_angle = 180-ball_dir-2*(ground_rotation);
if (bounce_angle<0) {
bounce_angle += 360;
}
speed = Math.sqrt((yspeed*yspeed)+(xspeed*xspeed));
xspeed = speed*Math.cos(bounce_angle*Math.PI/180)*friction;
yspeed = (speed*Math.sin(bounce_angle*Math.PI/180))*-1*friction;
_x = old_x;
_y = old_y;
}
else{
old_x = _x;
old_y = _y;
}
_y = _y+yspeed;
_x = _x+xspeed;
}
}
terrain is what the player draws.
terrain1 is the premade background.
I can attach the file or add the code for drawing (but the drawing seems fine).
Ball Vs Ball Collision Revisited
I know there are tons of posts dealing with ball vs ball collision and I have looked over any I could find, however none of them seem to work exactly like I want and I have been looking over examples for weeks now.
I have a script I modified from this site
(http://www.krazydad.com/bestiary/bes...superball.html)
that is pretty close but there is one problem I have yet to solve. Here is my modified code:
This part just updates the balls position based on their vx and vy variables. It gets called on a timer:
ActionScript Code:
public function moveBalls():void { var loopLength=ballArray.length-1; for (var count:int=0; count<=loopLength; count++) { var currentBall=ballArray[count]; var currentBallRadius=currentBall.ballRadius; currentBall.tempX = currentBall.x; currentBall.tempY = currentBall.y; currentBall.tempX += currentBall.vx; currentBall.tempY += currentBall.vy; if (currentBall.tempY-currentBallRadius<topEdge) { currentBall.tempY = topEdge+currentBallRadius; currentBall.vy *= -1; } else if (currentBall.tempY+currentBallRadius>bottomEdge) { currentBall.tempY = bottomEdge-currentBallRadius; currentBall.vy *= -1; } if (currentBall.tempX-currentBallRadius<leftEdge) { currentBall.tempX = leftEdge+currentBallRadius; currentBall.vx *= -1; } else if (currentBall.tempX+currentBallRadius>rightEdge) { currentBall.tempX = rightEdge-currentBallRadius; currentBall.vx *= -1; } } for (count=0; count<=loopLength; count++) { currentBall=ballArray[count]; for (var subCount:int=count+1; subCount<=loopLength; subCount++) { var currentSubBall=ballArray[subCount]; var xdiff:Number = currentSubBall.tempX-currentBall.tempX; var ydiff:Number = currentSubBall.tempY-currentBall.tempY; var dist:Number = Math.sqrt(xdiff*xdiff+ydiff*ydiff); if ((dist<=(currentBallRadius+currentSubBall.ballRadius)) && (!currentBall.isCollide ||!currentSubBall.isCollide) ) { currentBall.isCollide=true; currentSubBall.isCollide=true; doCollisionNew(currentBall,currentSubBall,dist,xdiff,ydiff); } else { currentBall.isCollide=false; currentSubBall.isCollide=false; } } } updateBalls();}
Next we actually update the balls real position:
ActionScript Code:
function updateBalls():void { var loopLength=ballArray.length-1; for (var count:int=0; count<=loopLength; count++) { var currentBall=ballArray[count]; currentBall.x = currentBall.tempX; currentBall.y = currentBall.tempY; }}
Ok, and here is the real part I'm having problems with. It gets called when there is a collision:
ActionScript Code:
function doCollisionNew(b1:BreakerBall, b2:BreakerBall,dist,xdiff,ydiff):void { var mag1 = Math.sqrt(b1.vx*b1.vx+b1.vy*b1.vy); var mag2 = Math.sqrt(b2.vx*b2.vx+b2.vy*b2.vy); if ( dist==0) { var angle = Math.atan2(ydiff,xdiff); var cosa = Math.cos(angle); var sina = Math.sin(angle); var diff = ((b1.ballRadius+b2.ballRadius)-dist)/2; var cosd = cosa*diff; var sind = sina*diff; b1.tempX -= cosd; b1.tempY -= sind; b2.tempX += cosd; b2.tempY += sind; b2.vx=-b1.vx; b2.vy=-b1.vy; b1.vx=-b2.vx; b1.vy=-b2.vy; } else { b2.vx = (mag1*xdiff/dist); b1.vx = -(mag2*xdiff/dist); b2.vy = (mag1*ydiff/dist); b1.vy = -(mag2*ydiff/dist); }}
Most of it is the same as jbum's script (http://www.krazydad.com/bestiary/bes...superball.html) except I added the part within the if statement ( if (dist==0) {....} ). This is kind of a hack, because I found if the balls are moving fast enough where they end up on top of each other, the vx/vy comes back as NaN and the balls end up stuck in the top left corner of the screen. Probably not the "right" way to do things, but it seems to work ok for my purposes.
Alright, so what I'm looking for is a random number of balls bouncing around the screen and colliding against each other in the simplest way possible. Everything works fine with this code, however if two balls start at the same Y position and travel down and toward each other, they collide wrong. Instead of moving outward from each other and continuing down, instead they just get stuck bouncing back and forth straight on x. Here is an example of this where ball1 starts at x=30, y=50 and ball2 starts at x=230, y=50. The first ball has vx=5, vy=5 and the second ball is vx=-5, vy=5.
http://metalblend.com/ballTest/proto-2a.html
This should work more like this:
http://metalblend.com/ballTest/proto-2b.html
The problem I see is that if the first balls vy is equal to the second balls vy then the variable ydiff is equal to zero. This causes this
ActionScript Code:
b2.vy = (mag1*ydiff/dist);b1.vy = -(mag2*ydiff/dist);
to set both balls vy to zero, making them 'stuck' on the x plane.
I can get it to work right (shown in the second link) using this script for the collision calculation instead:
ActionScript Code:
function doCollision(b1:BreakerBall, b2:BreakerBall, dist:Number, xdiff:Number, ydiff:Number):void { var angle = Math.atan2(ydiff,xdiff); var cosa = Math.cos(angle); var sina = Math.sin(angle); var vx1p = cosa*b1.vx+sina*b1.vy; var vy1p = cosa*b1.vy-sina*b1.vx; var vx2p = cosa*b2.vx+sina*b2.vy; var vy2p = cosa*b2.vy-sina*b2.vx; var P = vx1p+vx2p; var V = vx1p-vx2p; vx1p = (P-V)/2; vx2p = V+vx1p; b1.vx = cosa*vx1p-sina*vy1p; b1.vy = cosa*vy1p+sina*vx1p; b2.vx = cosa*vx2p-sina*vy2p; b2.vy = cosa*vy2p+sina*vx2p; var diff = ((b1.ballRadius+b2.ballRadius)-dist)/2; var cosd = cosa*diff; var sind = sina*diff; b1.tempX -= cosd; b1.tempY -= sind; b2.tempX += cosd; b2.tempY += sind;}
There are a couple problems with using the second script though. One of the main problems, is that I would like all the balls to stay at a constant speed after they collide. This is probably more of a "fake" collision, but that is what I am looking for. With this second function if you start all balls out with the same speed like vx=5,vy=5 for all balls, after bouncing for a bit, some start to move slower and some start to move faster.
Here is an example of this problem (using the more complex script):
http://metalblend.com/ballTest/proto-2c.html
The first script (jbum's) doesn't do this (they stay at a constant speed):
http://metalblend.com/ballTest/proto-2d.html
Also this second function has much more calculations to it and I'd rather keep it simple to avoid overhead and frame rate problems when dealing with a lot of balls bouncing. As well, this script is too confusing for me to understand for the most part .
So...if anyone knows an easy way to make the first script work right, without the problem of getting stuck on the x plane, MUCH APPRECIATED .
Oh,and the source file's I'm playing with can be downloaded here:
http://metalblend.com/ballTest/ballTest.zip
Ball VX And Ball VY Both Equal NAN
i have this script assigned to the ball, to bounce off of a circle, but when the ball hits the slime, somehow BallVX and BallVY are assigned the value of NAN, why is this happening?
ActionScript Code:
onClipEvent(load){
_global.ballVY = 0;
var maxXV = 15;
var maxYV = 22;
}
onClipEvent(enterFrame){
this._y += ++ballVY;
this._x += ballVX;
dx = 2*((_root.ball._x)-(_root.slime._x));
dy = (_root.ball._y)-(_root.slime._y);
dist = Math.sqrt(dx*dx+dy*dy);
dvx = ballVX - _global.P1XV;
dvy = ballVY - _global.p1YV;
if(dist < 52.5) {
something = (dx*dvx+dy*dvy)/dist;
_root.ball._x = (_root.slime._x) +(92.5)/2*dx/dist;
_root.ball._y = (_root.slime._y)+(92.5)*dy/dist;
if(something <= 0) {
ballVX += _global.P1XV-2*dx*something/dist;
if(ballVX < -maxXV)
ballVX = -maxXV;
if(_global.ballVX > maxXV)
ballVX = maxXV;
ballVY += _global.p1YV-2*dy*something/dist;
if(ballVY < -maxYV)
ballVY = -maxYV;
if(ballVY > maxYV)
ballVY = maxYV;
}
fP1Touched = true;
}
}
Ball Bouncing Within Another Ball
Hi,
I am trying to create a script so that a ball will be able to:
1) Start within a larger circle and move in a random direction and a random speed, and
2) Bounce off the inside walls of the larger circle.
I want to make it so that the ball will be able to bounce off the tangent of the larger circle at the point where they hit (so the bounce will be accurate), but I don't know where to begin...
I can make the ball start within the circle and start moving in a random direction and a random speed, but I've looked everywhere for any scripting reference to bouncing off tangents to a circle and I have found nothing for actionscript.
All help is greatly appreciated! Thx in advance!
Rolling Up
hello,
plz can anyone help me and tell me how to make a straight sheet rool up like a paper in flash ....
Rolling Over
I want my button to "jump out" when I roll over it.
I have created the whole thing, but when you roll over it, it loops.
bounce bounce bounce
how do I stop it?
it is not set to loop
Rolling Nav Bar
I'm new here, looking for some help. I'm not too experienced in Flash but my boss needs me to make a scrolling nav bar. Basically it will be a bar about 100 pixels high and 100% width at the bottom of the page. The point of the swf is almost a powerpoint, there are going to be 100+ pages/frames. The title box will be on display in the center bar taking up about 75% of the width with 5 or 6 next bars on the right and 5 or 6 previous bars on the left. If the user clicks the next button it will wipe onto the nav bar and squish the previously large title bar into a small bar on the left. I hope I've made this clear. Is there any type of script or anything that could help me to do this without making 100+ animation for each page?
Rolling Nav Bar
I'm new here, looking for some help. I'm not too experienced in Flash but my boss needs me to make a scrolling nav bar. Basically it will be a bar about 100 pixels high and 100% width at the bottom of the page. The point of the swf is almost a powerpoint, there are going to be 100+ pages/frames. The title box will be on display in the center bar taking up about 75% of the width with 5 or 6 next bars on the right and 5 or 6 previous bars on the left. If the user clicks the next button it will wipe onto the nav bar and squish the previously large title bar into a small bar on the left. I hope I've made this clear. Is there any type of script or anything that could help me to do this without making 100+ animation for each page?
Rolling Over
I am having problems with a button linked to a movie. The button and movie are right next to each other in the same frame. The idea is when I roll over the button the movie plays, but I cannot get the movie to play at all. I have put a stop command in the first frame of the movie to stop it from playing immediately. And I have the following action commands on the button:
on (rollOver) {
movie1.play();
}
Create Rolling Fog
Any ideas or Tut's on how to create a rolling fog effect.
Like a thichk fog dissapating to reveal, content.
Any help would be great.
Rolling Smoke
Does anyone have any insight, tips, tutorials or thoughts on how to accomplish a rolling smoke effect to be placed over an existing image?
Rolling Menu
im using a rolling menu and i can seem to be able to load pictures or text in to the menu. i got the menu from the www.macromedia.com site, it was one of them plug in type deals(or what ever they are called) if any one has ever used this or knows what im talking about how do i load the pics or the text?
Rolling And Bouncing
hi guys. i was just wondering if u could help me with sumthing. i wanted to learn how to make a box a draggable object, but when u drop it, it falls to the floor and like rolls and bounces a little. also depending on wot angle u do it at, it goes in that direction.
and FLA would be nice to learn from, but i was wondering if there are any tutorials that explain what each part of the script duz.
any help about this subject would be nice, thanx
Rolling Image
G'day all,
I need a little help. I am creating a web page for an architect and want to make a rolling strip of images which will continue to move across the screen and then loop. An example of what I am trying to do can be seen at this page http://www.daryljackson.com.au/
If anyone has seen a tutorial that describes how to do this could you please let me know.
Thanks for your help
Regards
Rolling Dice
Hi, can anyone help me making this dice's movement more fluent? I'd like it to roll in all directions, but just more fluid:
http://www.vetdesigner.it/flash
I'm attaching the FLA. I use AS1. Thanks!
Rolling Buttons
I am interested in making my buttons have a roll-over action as if when you roll over it an object appears to rise and when you roll off the object to another it falls. I understand that i need to make a movieclip for the rollover action but how to make a controller that tells it to fall or move when you rolloff. I just saw a sneaker ad for the allstar game that had button rollovers that were similar to what I wanted and rose and fell when you went over the name of the player.
Any help would be a ppreciated!
thanks
d
Rolling Over Movies
Is there an actionscript to change the color of a mc on the stage? it is going to play on release, but I want to button to look actionable when you roll over it.
thanks!
Rolling Buttons
I didnt know realy how to put this... I know this button effect is probably made with a movieclip button.... with OnRollOver and OnRollout actions. But mine are not quite working like theses.
I want to make that same effect but instead of going sideways the title of the button should animate verticaly...
Here is the buttons i want to recreate...
http://www.templatemonster.com/websi...tes/12331.html
[F8] Rolling Down A Slope
Im trying to make a ball or something roll down a slope or uneven surface. I've tryed using the tutorial at this website, but when the only problem with it is that the ball never stops bouncing.
so could someone please help me and make it so theball stops bouncing?
thanks
Rolling Dice
hi all
the only flash i know so far it is the one i do with text. but it's a work in process, slowly but surely. what i want to do is i guess animation; a rolling dice that will give an especific number always for instance; six all the time. or any number. can that be done? i'm sure it is possible but for me it 's a nightmare. i know there will be a lot of frames involve. can anyone help me with this task or point to a tutorial, a give me a sample. anything that can get me started and work on it.
i appreciate any feedback, help, cooperation, and your time.
thank you very much in advance
m.e.
[F8] Rollover Not Rolling Out...
Hello,
I have a flash movie (web site) that originally had a menu with 6 options.
I copied the last option twice, which gave me 2 additional menu items; a total of 8. I changed the instance names according to how all the other names were called in the respective actionscript areas.
My problem is that these last 2 menu's do not roll "out" (click through the menus 7 and 8 in the example.) Could anybody tell me what I may be missing here?
http://surf.california.com/test/
Flash 8
Actionscript 2
All comments appreciated.
Thanks
-Sean
Rolling On Impact?
Right, I have a standing, a running and a jumping MC, all in a hero MC all working.
I have the platforms and walls all good.
But I can't work it so that once I land a jump it will go to the "roll" MC.
Atm, when I jump I do a somersault and repeat it as needed, but if he lands halfway through a flip, it looks odd.
How do I get it so that on collision with "platforms" he will go to the rolling MC?
Cheers
I'll post my code if that helps?
Rolling Dice
hello i'm a beginner in actionscript
i'd like to know how i can make a dice roll by draging the mouse from side to side
i'd like it to roll from 3 to 1 AND from 2 to 1
referr to the image here http://azza.alameddine.free.fr/dice.jpg
thank u very much
|