• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker Animating sword code

J

JoeCruz

Guest
what im trying to accomplish: player presses attack key, creates weapon obj with image_angle pointed towards mouse, and step event rotates it, till alarm event activates and destroys it.

what my code is doing is creating the weapon obj, rotating it and..keeps rotating forever. I might be overlooking something simple. Any help would be much appreciated!




GML:
//weapon_obj create event:


can_rotate = 1;
image_angle = point_direction(x, y, mouse_x, mouse_y); //set to point towards mouse







////////////////////////////////////////////////////
// Weapon_obj step event:

        if (can_rotate == 1)
        {
    image_angle -= 4;         // "animation"
    alarm[0] = 4;
        }


move_towards_point(player_obj.x,player_obj.y,10);  //Sticks to the player




////////////////////////////////////////////////////////
//weapon_obj alarm[0] event:

instance_deactivate_object(self);





//////////////////////////////////////////////////////////////////
//weapon_obj draw event:


draw_self();
 

FrostyCat

Redemption Seeker
Set the alarm in the Create event, not the Step event. You don't want to prevent an alarm from counting down by continually setting it back up.

Also, destroying an instance is done with instance_destroy(), not instance_deactivate_object().
 
Top