Page 1 of 1

Lets take off into space! glitch

PostPosted: Mon Aug 01, 2011 9:22 pm
by Hblade
Um for some incredibly annoying reason when my character respawns (only from falling outside of the screen) he launches off into space at a very high velocity (Which makes absolutely NO SENSE what so ever at all, the falling code uses the same death code as colliding with an enemy... and when killed by the enemy you dont launch into oblivion so WTH?)
Death Codes:

Enemy Collision:
Code: Select all
DEAD=1;
PlaySound2("data/down a heart.wav", 1.000000, 1, 0.000000);


When fallen pass the view code:
Code: Select all
DEAD=1;
yvelocity=0;
PlaySound2("data/down a heart.wav", 1.000000, 1, 0.000000);

SO uh WTH the yvelocity=0 code was an attempt to fix the gltich..... but no it didnt do anything. Heres the code that executes in draw actor once the "DEAD" variable = 1
Code: Select all
if (DEAD==1) {
    transp=.99;
    yvelocity=0;
    CreateTimer("Event Actor", "respawn", 1000);
             }


So why does my character jump? heres the Create Timer code
Code: Select all
if (LIVES>0) {
    LIVES-=1;
    x=SPAWN[0];
    y=SPAWN[1];
    DEAD=0;
    yvelocity=0;
    DestroyTimer("respawn");
    view.x=-320;
    transp=0; }
if (LIVES==0) {
    LoadGame(""); }


Total Draw Actor Code:
Code: Select all
GetPad(10000, 10000); GetKeys(); SetGravity(.4);
DoGravity();
if (DEAD==0) {
    if (animindex==1 || animindex== 3 || animindex == 4) {
        dir=0; }
    if (animindex==0 || animindex==2 || animindex==5) {
        dir=1; }
    if (yscreen>=480) {
        yvelocity=0;
        DEAD=1;
        PlaySound2("data/down a heart.wav", 1.000000, 1, 0.000000); }
if (xscreen<620) {
if (GORIGHT) {
    x+=3;
    if (temp[1]==0) {
    ChangeAnimation("Event Actor", "RunRight", NO_CHANGE); }
    if (temp[1]==1) {
    ChangeAnimation("Event Actor", "JumpRight", NO_CHANGE); }
             }
                 }
if (xscreen>20) {
if (GOLEFT) {
    x-=3;
    if (temp[1]==0) {
    ChangeAnimation("Event Actor", "RunLeft", NO_CHANGE); }
    if (temp[1]==1) {
    ChangeAnimation("Event Actor", "JumpLeft", NO_CHANGE); }
                         }
                }

if (KEYRIGHT==1 && KEYLEFT==1) {
    if (animindex==0 || animindex==5) {
        ChangeAnimation("Event Actor", "StopLeft", NO_CHANGE); }
    if (animindex==1 || animindex==4) {
        ChangeAnimation("Event Actor", "StopRight", NO_CHANGE); }
                               }

if ((LXAXIS<los && LXAXIS>-los) && KEYLEFT==0 && KEYRIGHT==0) {
    if (animindex==0 || animindex==5) {
        ChangeAnimation("Event Actor", "StopLeft", NO_CHANGE); }
    if (animindex==1 || animindex==4) {
        ChangeAnimation("Event Actor", "StopRight", NO_CHANGE); }
                                                              }



if (xscreen>325) {
    view.x+=3; }
if (xscreen<315 && view.x>-317) {
    view.x-=3; }
if (xscreen<=20) { SSSS=1; }
if (xscreen>=620) { SSSS=1; }
if (SSSS==1 || VARS[1999]==1 && temp[1]==0) {
    if (animindex==0 || animindex==5) {
        ChangeAnimation("Event Actor", "StopLeft", NO_CHANGE); }
    if (animindex==1 || animindex==4) {
        ChangeAnimation("Event Actor", "StopRight", NO_CHANGE); }
             }
if (APRESS && temp[0]==0 && temp[1]==0) {
    temp[0]=1;
    yvelocity=-10;
    temp[1]=1; }

if (xscreen>20 && xscreen<620) {
    SSSS=0; }
    if (yvelocity>2) {
        temp[0]=1;
        temp[1]=1; }
if (yvelocity>-1 && yvelocity<1) {
    temp[1]=0;
                                 }
if (XPRESS && temp[2]==0) {
    temp[2]=1;
    PlaySound2("data/SILLYPOP.WAV", 1.000000, 1, 0.000000);
    CreateActor("bombs", "bomb01", "(none)", "(none)", 0, 0, false);
                          }
if (KEYX==0 && JoyX==0) {
    temp[2]=0; }
                  }
if (DEAD==1) {
    transp=.99;
    yvelocity=0;
    CreateTimer("Event Actor", "respawn", 1000);
             }



I hate glitches like this they dont make the least bit of freaking sense it's so frustrating!

Re: Lets take off into space! glitch

PostPosted: Tue Aug 02, 2011 1:14 am
by skydereign
Yeah, annoying, but most "glitches", save a couple, are actually because you as the programmer don't understand them, not because they cannot be understood. This particular glitch I do believe is gE's "fault", but it has to do with timers. This is what I got from a couple of minutes of looking around (could be wrong). Timers don't use the normal frame by frame system, so they trigger at irregular points, based off your timer. gE seems to have some problems setting velocities during timer events, when other events also are altering velocity. So if the timer event goes off when other scripts are editing the variable, it will have problems. It is probably a bit more complex, but generally that is it. It seems more than just a problem with not updating the new velocities, as sometimes they take massive leaps each time it tries to set it to 0 by timer.

Anyway, a fix is to not use a timer, and instead use a timer variable.
Code: Select all
if(DEAD==1)
{
    transp=0.99;
    yvelocity=0;
    timer++;
    if(timer>=30)
    {
        //timer event
    }
}

Or edit wherever you handle gravity to not increase it while the actor is dead. So, only increase or set yvelocity when the actor is not dead. That should fix it as well.

Re: Lets take off into space! glitch

PostPosted: Tue Aug 02, 2011 5:26 am
by Hblade
Thank you very much sky :) Much appreciated.