#Top down melee attacks aim

1 messages · Page 1 of 1 (latest)

teal mountain
#

other then var playerCenterX = x + sprite_width / 9; looking like a roundabout way to change the origin point of a sprite there is no flaw in the coding. what do you want the code to do and what is the incorrect output?

royal coral
#

Well it sets an alarm for 9 seconds but then it destroys itself once its created, don't know if that'll help though

#

I mainly want the attack to aim in the direction you click though, currently it sets the object in the direction you click, but it doesn't change the sprite to face where you clicked

teal mountain
royal coral
royal coral
#

Okay, so it didn't work out well, either it would say that the variable "dir" was not described if I put it in the hitbox object, and if I put it in the player, the player would face the direction of the hitbox, and ideas on how to fix this?

royal coral
#

Nevermind I have it figured out, the only problem is that it continues to look towards my mouse after its created, and idea on how to lock an image_angle in place?

teal mountain
#

not set it

royal coral
#

Well it doesn't have set before image angle, here have a look at the code

#

if (mouse_check_button_pressed(mb_left))
{
var playerCenterX = x + sprite_width / 9;
var playerCenterY = y + sprite_height / 6;

    var dir = point_direction(playerCenterX, playerCenterY, mouse_x, mouse_y);
    
    var LEN = 32;
    var hitboxX = lengthdir_x(LEN, dir) + playerCenterX;
    var hitboxY = lengthdir_y(LEN, dir) + playerCenterY;
    
    var hitbox = instance_create_depth(hitboxX, hitboxY, depth, Ohitbox);
    with (instance_create_layer(x,y,Ohitbox,Ohitbox))
        {
        direction = other.image_angle;
        image_angle = direction;
        }
    hitbox.creator = id;
}
#

Heres the player event

#

And the hitbox event

#

image_angle = point_direction(x,y,mouse_x,mouse_y);

teal mountain
#

the image_angle = point_direction(x,y,mouse_x,mouse_y); is making it point towards your cursor every frame. if you dont want it to then get rid of the line.