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! :(