Legacy GM Trying to get my player to shoot upwards.

pixeltroid

Member
I have this in my players step event:
if keyboard_check(ord("F")) && health > 0 && (place_meeting(x,y+1,obj_solid))
{ pointup = true; }
else
{ pointup = false; }
if (pointup = true)
{
sprite_index = spr_pointup
}
This in my keypress button:
if (state == 'move' && pointup = true){
sprite_index = spr_pointup ;
}
This in my player shooting script:

if (bullets > 2 && state == 'move' && pointup = true)
{
b=instance_create(x,y-30,obj_bullet);
b.speed = 9;
b.direction = 90;
}
bullets -= 1;
if (alarm[7] == -1) alarm[7] = (room_speed / 4);
Im just getting the sprite to change but the bullets still shoot sideways. How do I fix the code to shoot upwards?
 

Slyddar

Member
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;
 
S

spoonsinbunnies

Guest
does your bullet have any coding in it that forces sideways movement?
 

TheouAegis

Member
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.
 

pixeltroid

Member
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.
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

//if(keyboard_check(ord('O'))) {
if (bullets > 2)
{
if (obj_player.ducking == true && pointup = false) {
b=instance_create(x+6,y-1,obj_bullet);
b.speed = 9;

if (image_xscale > 0) {
b.direction = 0;
}
else
{
b.direction = 180;
}
}
else {
b=instance_create(x+6,y-8,obj_bullet)
b.speed = 9;
if (image_xscale > 0) {
b.direction = 0;
}
else {
b.direction = 180;
}
}
bullets -= 1;
}
if (alarm[7] == -1) alarm[7] = 7


//shoot up

if (bullets > 2)
{
if (pointup = true && obj_player.ducking == false)
{
b=instance_create(x+6,y-1,obj_bullet);
b.speed = 9;
b.direction = 90;

}
bullets -= 1;
}
if (alarm[7] == -1) alarm[7] = 7
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/
 

TheouAegis

Member
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.
 

pixeltroid

Member
@TheouAegis

I made a few changes:

Player step event
if keyboard_check(ord("F")) && health > 0 && (place_meeting(x,y+1,obj_solid))
{ pointup = true; }
else
{pointup = false; }

if (pointup = true)
{
sprite_index = spr_pointup
}

//conditions for shooting upwards
if keyboard_check(ord("O")) && pointup = true //playermust point up and press shoot button 'O'
{
state = 'playershootup'
}
Separate script for shooting upwards 'PLAYERSHOOTUP'

if (bullets > 2)
{
b=instance_create(x+6,y-1,obj_bullet);
b.speed = 9;
b.direction = 90;
}
bullets -= 1;

if (alarm[7] == -1) alarm[7] = 7
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:

TheouAegis

Member
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

Member
@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.
 
Top