1. Hey! Guest! The 34th GMC Jam will take place between August 22nd, 12:00 UTC (Thursday noon) and August 26th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

GM:S 1.4 Trying to get my player to shoot upwards.

Discussion in 'Programming' started by pixeltroid, Feb 22, 2019.

  1. pixeltroid

    pixeltroid Member

    Joined:
    Jul 23, 2016
    Posts:
    603
    I have this in my players step event:
    This in my keypress button:
    This in my player shooting script:

    Im just getting the sprite to change but the bullets still shoot sideways. How do I fix the code to shoot upwards?
     
  2. TheSly

    TheSly Member

    Joined:
    Jan 16, 2017
    Posts:
    949
    Do you mean the angle of the bullet is wrong? If so set the image_angle after you set the direction.
    Code:
    b.image_angle = b.direction;
    
     
  3. pixeltroid

    pixeltroid Member

    Joined:
    Jul 23, 2016
    Posts:
    603
    i meant the bullets fire sideways instead of going upwards at 90 degrees
     
  4. spoonsinbunnies

    spoonsinbunnies Member

    Joined:
    Aug 24, 2018
    Posts:
    66
    does your bullet have any coding in it that forces sideways movement?
     
  5. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    6,642
    Post your ENTIRE shooting code.
    Also, post the code that calls the shooting script.
    Does your shooting up code have a separate script from the shooting horizontally code? If so, make sure you called the right script.

    Odds are, the bullet has code, as the other guy stated. But there's also a possibility the normal shooting script is overriding.
     
  6. pixeltroid

    pixeltroid Member

    Joined:
    Jul 23, 2016
    Posts:
    603
    The bullet does not have any code apart from how it interacts with enemies.

    Heres my entire shoot script that determines shooting while standing, ducking and pointing upwards

    Shooting while standing and ducking works fine. But the second chunk of the code to make player shoot while pointing up isnt working.
    Any idea what Im doing wrong/
     
  7. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    6,642
    Your first code block says "If i'm ducking, shoot low, else shoot normally." That leaves you no chance for shooting up. You probably have your ammo amount set to 3 by default, right? So your code shoots the first bullet as normal and decreases your bullet count. Now bullets==2, which means it's not the case any more that bullets>2, so the shooting up code doesn't run. If you set your bullets to 100 by default, you should see your gun shooting BOTH up and normal every time you try to shoot up. You need to incorporate your shooting up code INTO the rest of your shooting code. You cannot treat it separately like you are doing there.
     
  8. pixeltroid

    pixeltroid Member

    Joined:
    Jul 23, 2016
    Posts:
    603
    @TheouAegis

    I made a few changes:

    Player step event
    Separate script for shooting upwards 'PLAYERSHOOTUP'

    It mostly works....except that while shooting up the player (in his pointing upwards sprite) also shoots horizontally (At a slower rate) in the direction he is facing. Any idea what Im doing wrong?
    i guess the code does not prevent player from shooting sideways while in the shoot upwards mode. How do I remedy this?

    note: The reason I have a seperate script and conditions to shoot upwards is because I have more than 1 weapon, and handling the various shooting conditions in one script sounds to complicated for me.
     
    Last edited: Feb 23, 2019
  9. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    6,642
    So you have a separate state for shooting up, but is your normal shooting code still outside the scope of your state machine? Also your shooting up code doesn't seem to use the alarm as a conditional.
    Code:
    if keyboard_check(ord("O")) 
    {
        if pointup= true 
        {
            state = 'playershootup' 
        }
        else
        if ducking= true
        {
            state = 'playershootduck';
        }
        else
        {
            state = 'playershootstand';
        }
    }
    

    Combining your conditionals might help a little bit too.
     
    pixeltroid likes this.
  10. pixeltroid

    pixeltroid Member

    Joined:
    Jul 23, 2016
    Posts:
    603
    @TheouAegis


    hey i think i got it to work. I think the problem was that the conditions for shooting sideways was being met while shooting upwards. Thats why my player was shooting sideways and upwards simultaneously.

    So I added code like this into my players step event:

    Code:
    if state = 'playershoot' {
    pointup = false
    } 
    
    if ducking = true {
    pointup = false
    }
    
    if pointup = true{
    canshoot = false}
    
    if pointup = false{
    canshoot = true}
    
    etc
    
    this way he shoots while ducking/standing/pointing up only when specific conditions are met.

    my code is a mess really as it had been written with the help of various tutorials and posts.
     

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