
I'm trying to change the ball object's direction to the same angle as the player's origin to the point of collision between the bat and the ball. I'm using the grandma engine's hspd and vspd variables and I'm not sure how to determine the correct angle while adding a bit of speed to it.
Here's what I have so far:
Ball's collision event with the player's bat
var pdist;
pdist=sign(point_distance(x,y,obj_player.x,obj_player.y))+max(hspd,vspd);
hspd=lengthdir_x(pdist,point_direction(obj_player.x,obj_player.y,x,y));
vspd=lengthdir_y(pdist,point_direction(obj_player.x,obj_player.y,x,y));
//adds speed to the ball each hit
hspd+=sign(hspd)*1.5
vspd+=sign(vspd)*1.5;
//So the ball is always hit to the left
if sign(hspd)!=-1
hspd*=-1;
I'm getting some strange results from this code. Any help would be greatly appreciated!