|
-
Dot Product, Please Help Me!!!
Hi I've been working on this game engine for about 2 months and have been stuck 75% of that time on a collision between the player and a 45 degree slope.
I'll try and explain my engine best as possible:
PHP Code:
Mouse.hide(); _global.dday = 0; _global.angCol = 0;
///Helpful if(_global.dday == 1){ hit = 1; }else{ hit = 0; } moveP = 1; mouseDist = 12; //Gravity grav = 1;
///Speed Variables speed_x = 0; speed_y = 0;
///Acc Variables acc_x = 1; acc_y = 1;
///Dec Variables dec_x = 0.95; dec_y = 0.95;
//Size Variables Radius = _root.player._width/2;
//User Code _root.player.onEnterFrame = function() { //Location Shortcut _global.player_y = _root.player._y; _global.player_x = _root.player._x; //Trace Boxes _root.box1 = playerFin; _root.Xbox = Math.round(speed_x); _root.Ybox = Math.round(speed_y); ///Move Player _root.player._y += speed_y; _root.player._x += speed_x; //Gravity speed_y += grav; //Friction/Air Resistance speed_y *= dec_y; speed_x *= dec_x; ///Shortcut Variables Xm = _root._xmouse; Ym = _root._ymouse; Xp = _root.player._x; Yp = _root.player._y; Adj = Xm-Xp; Opp = -1*(Ym-Yp); Ang = Math.atan2(Opp, Adj); Fin = Math.round(Ang/Math.PI*180); playerRadins = Math.atan2 (speed_y, speed_x); playerAng = Math.round(playerRadins * 180 / Math.PI); playerFin = playerAng; //Custom Cursor _root.cursor._x = Xm; _root.cursor._y = Ym; //Boundries Collisions if (_root.player._y>=400) { Yinvert(Yinvert); } if (_root.player._y<=0) { Yinvert(Yinvert); } if (_root.player._x>=750) { Xinvert(Xinvert); } if (_root.player._x<=0) { Xinvert(Xinvert); } //The Lenght of the Hyp between the mouse and player //Hyp = Math.sqrt(((player.y - mouseY) * (player.y - mouseY)) + ((player.x - mouseX) * (player.x - mouseX))); }; function trigHit(trigHit) { if(_global.dday == 1){ hit = 1; } } function untrigHit(untrigHit) { if(_global.dday == 1){ hit = 0; } } //Horizontal Collision function Xinvert(Xinvert) { speed_x -= (speed_x*2); } //Vertical Collision function Yinvert(Yinvert) { speed_y -= (speed_y*2); untrigHit(untrigHit); } //Dot Product Collision, NEEDED HERE! function Zinvert(Zinvert) { } //This Launches the ball in the direction onMouseDown = function () { if (hit == 0) { speed_y = (_root._ymouse-_root.player._y)/mouseDist; speed_x = (_root._xmouse-_root.player._x)/mouseDist; trigHit(trigHit); } };
The SWF
I want to know what I have to do to the players x_speed and y_speed after the collision with the 45 degree slope I know it involves dot product I've done alot of research into it, but no luck.
Research Links:
2D Physics Tutorial
TONYPA: Bounce
Math World: Dot Product
THE .FLA: http://www.filefreak.com/pfiles/70453/SpaceHopper.fla
PLEASE DON'T STEAL MY WORK!
PLEASE CAN SOME ONE HELP ME I'VE BEEN STUCK ON THIS PROBLEM FOR A MONTH NOW!
Last edited by unrealhacker12; 08-20-2008 at 03:16 PM.
-
Developing For Dunkets
I'm not a big math guy, but I swear I've seen a fla on senocular's site that has some trajectory info on angled slopes. I know I've seen it somewhere and I'm thinking that's it.
http://senocular.com/flash/source.php?id=0.175
Search through the source files page. Check out the rest of the site too. Not a flashy site but tons of serious, practical flash work that is there for dissecting.
-
Could see anything in his Source .fla's :S
-
Developing For Dunkets
have you been to http://www.kirupa.com and browsed the tutorials? Or, have you checked the math and physics tutorials on FK? Or maybe I saw it somewhere here:
http://www.flashperfection.com/tutor...als-26531.html
Ahab's Math tuts are pretty rocking. I've done half of anything involving math with help from this site. I'll check around some more too and see if I can't find the exact one. I know I had a fla with the answer to your problem and I played with it for hours. I'll find it again.
-
Thank you very much you have no idea how much I appreciate your help.
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
|