|
-
Senior Member
[F8] Vectors help
I can get this vector stuff to work, going from moving a vector to making a vector bounce is a huge gap and I dont know how to get across.
Code:
// Declair Objects
Ball = {};
Wall = {};
// Balls First Point
Ball.p0 = {x:100, y:100};
// Wall First and Second Points
Wall.p0 = {x:380, y:120};
Wall.p1 = {x:380, y:200};
// Direction Components
Ball.vx = 1;
Ball.vy = 0;
Wall.vx = Wall.p1.x-Wall.p0.x;
Wall.vy = Wall.p1.y-Wall.p0.y;
// Main Function
onEnterFrame = function () {
// Move the MC MainBall to the current Ball vector
MainBall._x = Ball.p0.x;
MainBall._y = Ball.p0.y;
// Calculate the end point using the Direction Components
Ball.p1 = {};
Ball.p1.x = Ball.p0.x+Ball.vx;
Ball.p1.y = Ball.p0.y+Ball.vy;
// Make the first vector equal to the second vector
Ball.p0 = Ball.p1;
// Left Hand Norma of Wall
Wall.lx = Wall.vy;
Wall.ly = -Wall.vx;
// Dot Producted Between ball and wall
dp1 = Ball.vx*Wall.vx+Ball.vy*Wall.vy;
// projection of movement vector on the v2:
proj1.vx = dp1*Wall.dx;
proj1.vy = dp1*Wall.dy;
//reversing projection on the normal:
proj2.vx *= -1;
proj2.vy *= -1;
//finding new movement vector by adding up projections:
Ball.vx = proj1.vx+proj2.vx;
Ball.vy = proj1.vy+proj2.vy;
// The rest of the code just changes the direction componeants
// and resets the vector to the oposite side if it goes out of the stage.
}
That is what i have, i have been trying to follow tony's tute's, the first bit is heeps easy to follow wen well writting, but the whole bonce thing i dont get, it explains everything and how it works but I dont understand how the code does what it does. I downloaded the souce and its nothing like the stuff on his site so i found no use to it at all, is the code on his site just to show how stuff works and not actualy making the ball bounce?
Can some one have a look over my code and tell me what I have done and what needs to be done.
The italic code is the most recent stuff i added, once i added it my vector no longer moves.
Cheers
92.7 Fresh FM for all your South Aussies - Doof Doof music FTW people!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|