Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 07-13-2012, 08:38 AM   #1
cez
Registered User
 
Join Date: Jul 2012
Posts: 1
Default Drag and Drop, Collision + Gravity

First of all Hello to you all as I am new to the community.

I need some help with flash, bear in mind I am a flash noob.
Basically I am trying to create a greek building made of roof being on top of 4-5 columns standing on top of a fixed position floor, but when you remove one of the pillars the roof will collapse and blow up or something like that

I have found on the web a free script with drag and drop/collision/gravity and i have modified as much as I could and now Im stuck with the objects within the file being circles and the collision works for circles and I need it to be squares/rectangles so it can be replaced with a column later on. I already replaced the circle with a square but the collision still detects it as a circle.


I belive everything within the function collisionDetect() { } is responsible for the detection of the circle shape, have no idea how to modify it though


ActionScript Code:
balls = new Array(); for (var i = 0; i < 5; i++) {     myBall = attachMovie("ball", "ball" + i, i);     balls.push(myBall);     myBall.vx = 0;     myBall.vy = 0;     myBall._x = Math.random() * Stage.width;     myBall._y = Math.random() * Stage.height;     myBall.onEnterFrame = ballMove;     myBall.onPress = ballPress;     myBall.onRelease = myBall.onReleaseOutside = function () {         stopDrag();         this.onEnterFrame = ballMove;     }; } ballRadius = ball0._width / 2; leftWall = 0 + ballRadius; rightWall = Stage.width - ballRadius; topWall = 0 + ballRadius; bottomWall = Stage.height - ballRadius; ballLength = balls.length; onEnterFrame = function () {     collisionDetect();     getEnvironment(); }; function getEnvironment() {     yGravity = 1;     friction = 1;     frictionShow = Math.abs(Math.round(friction * 100) - 100) + " Friction";     bounce = 0;     bounceShow = Math.abs(Math.round(bounce * 100) - 100) + " Bounce"; } function ballMove() {           this.vy += yGravity;     this.vx += xGravity;     this.vy *= friction;     this.vx *= friction;     this._x += this.vx;     this._y += this.vy;     if (this._x < leftWall) {         this._x = leftWall;         this.vx *= -bounce;         this.vy *= bounce;     }     if (this._x > rightWall) {         this._x = rightWall;         this.vx *= -bounce;         this.vy *= bounce;     }     if (this._y > bottomWall) {         this._y = bottomWall;         this.vy *= -bounce;         this.vx *= bounce;     }     if (this._y < topWall) {         this._y = topWall;         this.vy *= -bounce;         this.vx *= bounce;     } } function ballPress() {     delete this.onEnterFrame;     this.onEnterFrame = function() {         startDrag(this);         this.vx = this._x - this.oldx;         this.vy = this._y - this.oldy;         this.oldx = this._x;         this.oldy = this._y;     }; } function collisionDetect() {     for (var i = 0; i < ballLength - 1; i++) {         tempBall1 = balls[i];         for (var j = i + 1; j < ballLength; j++) {             tempBall2 = balls[j];             var dx = tempBall1._x - tempBall2._x;             var dy = tempBall1._y - tempBall2._y;             var distance = Math.sqrt(dx * dx + dy * dy);             if (distance < ballRadius * 2) {                 var angle = Math.atan2(dy, dx);                 var cos = Math.cos(angle);                 var sin = Math.sin(angle);                 tempBall1._x = tempBall2._x + cos * (ballRadius * 2);                 tempBall1._y = tempBall2._y + sin * (ballRadius * 2);                 tempBall2._x = tempBall1._x - cos * (ballRadius * 2);                 tempBall2._y = tempBall1._y - sin * (ballRadius * 2);                 var vx2 = cos * tempBall1.vx + sin * tempBall1.vy;                 var vy1 = cos * tempBall1.vy - sin * tempBall1.vx;                 var vx1 = cos * tempBall2.vx + sin * tempBall2.vy;                 var vy2 = cos * tempBall2.vy - sin * tempBall2.vx;                 tempBall1.vx = cos * vx1 - sin * vy1;                 tempBall1.vy = cos * vy1 + sin * vx1;                 tempBall2.vx = cos * vx2 - sin * vy2;                 tempBall2.vy = cos * vy2 + sin * vx2;             }         }     } }

Ive pasted the code and attached the file for your needs.



Any help would be greatly appreciated.
Attached Files
File Type: zip modCS5.zip (7.8 KB, 30 views)
cez is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 04:22 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.