Angry Birds - getting player to follow mouse from a distance

M

Matt93

Guest
I'm creating a slingshot, similar to Angry Birds. At the moment, there is no limit as to how far back I can drag the slingshotr. I want to only be able to pull back the slingshot 300 pixels, but also want the player to still move with the mouse when it's beyond this point, without being able to actually pull back the slingshot any further. Like in Angry Birds when the bird will continue to tilt, even when your finger has pulled the slingshot to its limit. I think you need trig functions to do this, so have been trying with lengthdir_x and lengthdir_y. I have this so far in the player object.

Code:
if (held) //set to true when player clicked
{
    throw = true; //player can be thrown
    dir = point_direction(obj_sling.x, obj_sling.y, mouse_x, mouse_y);
    dist = point_distance(obj_sling.x, obj_sling.y, mouse_x, mouse_y);
    if (dist < 300) //within distance
    {
        x = mouse_x + lengthdir_x(0, dir)
        y = mouse_y + lengthdir_y(0, dir)
    }
    else
    {
             
    }
}
I don't know what to put in the else statement. Any help would be really great, as I'm quite stuck on this. Cheers!
 

jo-thijs

Member
x = obj_sling.x + lengthdir_x(300, dir);
y = obj_sling.y + lengthdir_y(300, dir);

and also get rid of:
+ lengthdir_x(0, dir)
+ lengthdir_y(0, dir)
It's ugly.
 
M

Matt93

Guest
x = obj_sling.x + lengthdir_x(300, dir);
y = obj_sling.y + lengthdir_y(300, dir);

and also get rid of:
+ lengthdir_x(0, dir)
+ lengthdir_y(0, dir)
It's ugly.
Simple solution. I'd been trying the same code, but with mouse_x + lengthdir_x and mouse_y + lengthdir_y for some reason. Thanks!
 
Top