fire a projectile based on image angle

Discussion in 'Programming' started by redbeard990, May 23, 2017.

  1. redbeard990

    redbeard990 Guest

    I know this is probably simple, but I cannot seem to get my projectile to fire correctly. I need it to fire from the center of the sprite, and in the direction, the sprite is facing. I have a player object and a bullet. I do not want to fire at the mouse_x or mouse_y.
     
  2. IndianaBones

    IndianaBones Member

    Joined:
    Jul 5, 2016
    Posts:
    2,200
    How are you setting the direction of the sprite at the moment? What are the sprite origin settings for your player and bullet sprites?

    Can you post the bullet firing code you are using? And describe what is happening when you do fire the bullet with your current code.

    In the meantime, when you create the bullet, you'd use some version of setting the bullet x and y to the player x and y, and adjust for the origin offset as necessary. Then you'd set the direction and image_angle of the bullet to be the same as the player sprite.

    Also, are your sprites all drawn with their default position facing to the right, i.e., the direction of 0 degrees in GameMaker. That makes things easier in general.

    I'm off to bed but either someone else can reply sooner, or I'll have a look the next chance I get.
     
  3. obscene

    obscene Member

    Joined:
    Jun 21, 2016
    Posts:
    2,423
    You should be able to use the image_angle of what's firing it.

    ie.
    with instance_create(x,y,obj_bullet) direction=other.image_angle;
     
  4. Murzy

    Murzy Member

    Joined:
    Jul 28, 2016
    Posts:
    24
    Something like this?

    Code:
    var projectile = instance_create(x, y, obj_bullet); // Create a bullet
    var launchSpeed = 32;
    
    projectile.direction = image_angle; // Set movement direction to the launcher's angle
    projectile.image_angle = image_angle; // Set projectile facing to the to the launcher's angle
    projectile.speed = launchSpeed; // Set the speed of the projectile
    
     
  5. redbeard990

    redbeard990 Guest

    Thank you for the replies. It is working now, I was setting the direction wrong!
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice