Finding bounce angle on angled surfaces..?

Hello, new poster here :slight_smile:

I am desperate to find a solution to this issue. Basically, I am making a game in which there is a character (charMC). When you hold down your mouse, you can rotate the character. You point it in a direction, release the mouse, and it goes that direction. When it collides with an obstacle (like a wall), it should bounce off appropriately. And that’s my issue…

I’m using Corey O’Neil’s Collision Detection Kit to handle my collision detection. This kit returns a “collision angle” which, in Mr. O’Neil’s words: “It is finding THE angle of collision - the shared normal between the two objects based on their shapes at the point of collision. To phrase it another way, it’s the perpendicular to the tangent line shared by both objects at the point of collision.”

I can’t figure out how to use this “collision angle” to calculate the outgoing angle – basically, I need to use this angle to change the charMC’s rotation to the appropriate value.

Relevant Code:


function pushChar(e:Event) { // called when the mouse is released

           // mouse can no longer affect character
            charMC.controllable = false; 

            var charPos:Point = new Point(charMC.x,charMC.y);
            var cursPos:Point = new Point(mouseX,mouseY);

            // if the mouse is farther away from the character, 
            // the character goes faster (and vice-versa)
            var pushStrength:Number = Point.distance(charPos,cursPos);

            if (pushStrength > maxPush) {
                pushStrength = maxPush;
            }

            speed = (pushStrength/maxPush) * maxSpeed;


             vx +=  Math.sin(GlobalMath.degreesToRadians(charMC.rotation)) *speed;
             vy +=  Math.cos(GlobalMath.degreesToRadians(charMC.rotation)) * -speed;
        }


public function moveLevel():void { // called every timer tick 
            checkBounds();
            
            charMC.x +=  vx;
            charMC.y +=  vy;

            vx *=  friction;
            vy *=  friction;
        }

private function checkCollisions():void {
            // cList is a CollisionList
            var colls:Array = cList.checkCollisions();

            for(var i:int = 0; i < colls.length; i++)
            {
                // Grab the next collision in the array
                var coll:Object = colls*;
                
                var angle:Number = coll.angle;
                var overlap:int = coll.overlapping.length;
                
                // make sure we're choosing the character, not the hittable object
                if(colls.object1 is Cuttle) 
                    var collChar = colls.object1;
                } else {
                    var collChar = colls.object2;
                }
                
                charMC.rotation = GlobalMath.radiansToDegrees(coll.angle);
                
                vx +=  Math.sin(GlobalMath.degreesToRadians(charMC.rotation)) * speed;
                vy +=  Math.cos(GlobalMath.degreesToRadians(charMC.rotation)) *  -speed;
            
            }

Attached is the swf in its current state. EDIT: Err, is it attached? Sorry, I can’t figure Kirupa out…

Any help or insight would be MUCH appreciated. I am at my wit’s end here :frowning: