Help needed with projectile's place of origin.

Discussion in 'Programming' started by Xerona_Jole, Mar 14, 2019 at 7:35 AM.

Tags:
  1. Xerona_Jole

    Xerona_Jole Member

    Joined:
    Feb 26, 2019
    Posts:
    6
    Hello!

    I am a beginner and not a native English speaker so please have patience with me.

    I have a minor problem that is probably easily fixed with knowledge so after few hours of listening to New Order and trying to figure this out myself I thought I should just ask you guys.

    The game is in 2-D so I won't be having mouse following my characters movement. The problem I have is that when the character is moving left the bullet projectile comes from the same place as it does when moving to the right. Now I've fiddled around with some code to make it come from a different place but I just can't figure it out.

    So I have variables LenX and LenY for the distance between the sprite centre and the tip of the gun.

    Here's my shooting code:

    //Shooting
    firingdelay = firingdelay -1;
    if key_shoot and (firingdelay < 0)
    {
    firingdelay = 8;
    with (instance_create_layer(x + lengthdir_x (LenX, image_angle) - lengthdir_y (LenY, image_angle), y + lengthdir_y (LenX, image_angle) + lengthdir_y (LenY, image_angle),"bullet", obj_bullet))
    {
    facing = other.facing;
    spd = 15;
    }
    }

    And I've tried to use things like:
    if (other.facing < 0)
    { LenX = - 21 }
    or
    if other.facing = -1
    { LenX = - 21 }

    However these don't seem to affect the LenX at all.
     
  2. marasovec

    marasovec Member

    Joined:
    Sep 15, 2016
    Posts:
    221
    Maybe use
    Code:
    var b = instance_create_layer(x + lengthdir_x (LenX, image_angle) - lengthdir_y (LenY, image_angle), y + lengthdir_y (LenX, image_angle) + lengthdir_y (LenY, image_angle),"bullet", obj_bullet))
    b.facing = facing;
    b.spd = 15;
    
    EDIT:
    Where is this code from?
    From the player or the bullet?
    Code:
    if (other.facing < 0)
    { LenX = - 21 }
    or
    if other.facing = -1
    { LenX = - 21 }
    
     
  3. Xerona_Jole

    Xerona_Jole Member

    Joined:
    Feb 26, 2019
    Posts:
    6

    From the player. I try to figure how I could use the code you suggested. Thank you for your help already :).
     

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