Jump to content
A 2021 backup has been restored. Forums are closed and work in progress. Join our Discord server for more updates! ×
SoaH City Message Board

Cannon angle problem(GM8)


Recommended Posts

There are a few topics on this, but I still can't seem to figure the problem. I'm having trouble trying to program a cannon that will shoot the player in the same direction of the cannons angle(at the speed of 35). Sometimes it will shoot in the right direction and other times not. I'm using GM8.

Creation event:

on=0; //off or ready to fire

tar=0; //identify which player

smokeCount=15; //smoke particles

acc=0; //cannons rotation speed

ang=0; //cannons angle

catchOK=1; //Is it ok to hop in cannon

Alarm 0: //Smoke particles

if (smokeCount>0)

{

instance_create(tar.x,tar.y,burnSmoke);

smokeCount-=1;

alarm[0]=5;

}

Alarm 1: //Ready to shoot again

catchOK=1;

Collision event: //with Player1's parent object

if (other.vsp>0 && on==0 && catchOK==1)

{

on=1;

tar=other.object_index;

smokeCount=15;

}

Step event:

if (on==1)

{

tar.x=x;

tar.y=y;

tar.hsp=0;

tar.vsp=0;

tar.action=1; //jump

if (tar.KEY_LEFT) acc+=0.15;

if (tar.KEY_RIGHT) acc-=0.15;

if (ang>155) {ang=155;acc=0;}

if (ang<25) {ang=25;acc=0;}

if (acc>3) acc=3;

if (acc<-3) acc=-3;

if (abs(acc)>0) acc*=0.95;

ang+=acc; //adjust cannon direction

image_angle=ang;

//fire player

if (tar.KEY_A)

{

tar.hsp=cos(ang)*35;

tar.vsp=sin(ang)*35;

sound_play(turFireSnd);

instance_create(x,y,burnSmoke);

alarm[0]=5;

alarm[1]=50;

on=0;

catchOK=0;

}

}

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...