Question

I hav bee struggling with a collision response method, im writing in actionscript 3, for a long time now, and I am hoping someone can explain what this code means, for I have only modified it. I did not write it from scratch. also I am using the Collision Detection Toolkit to find where the collisions are happening.
What im trying to do is make it so that Ball (which is the object that you move around the screen with your keyboard) hit's a wall or object it will not go through the wall or object.

my understanding of this is that you are finding the angle that the collision is happening at and then you need to find the angle which is adjacent which is the new vector and push back the object by however much it's overlapping, but I dont understand how this function works for instance what is

vx0:Number = ball.vx * cos + ball.vy * sin;

finding?. in addition I dont want the ball to accelerate I want it's velocity to be constant until it hits an object. also would it be faster to search through this array backwards?

-- I appreciate any one who takes the time to try and help me with this, and im sorry if I have some misspellings.

     for(i = 0; i < collisions.length; i++) 
        {
            var collision:Object = collisions[i];

            var angle:Number = collision.angle;
            var overlap:int = collision.overlapping.length;
            var ball:Ball = collision.object1;

            var sin:Number = Math.sin(angle);
            var cos:Number = Math.cos(angle);

            var vx0:Number = ball.vx * cos + ball.vy * sin;
            var vy0:Number = ball.vy * cos - ball.vx * sin;

            vx0 = .4;
            ball.vx = vx0 * cos - vy0 * sin;
            ball.vy = vy0 * cos + vx0 * sin;

            ball.vx -= cos * overlap / ball.radius;
            ball.vy -= sin * overlap / ball.radius;
        }

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top