Page 1 of 1

Give gravity to multiple characters?

PostPosted: Wed Feb 02, 2011 3:04 pm
by ThaKid244
Hi. I have two characters, i give both of them a yvelocity++; gravity in their respective draw actors. but one is weighed down like a heavy rock. Can someone give me a way to solve this problem or tell me how to give gravity to mulitple characters w/out one being weighed down? thanks

Re: Give gravity to multiple characters?

PostPosted: Wed Feb 02, 2011 4:31 pm
by Hblade
Whats the code for the one thats heavy?

Re: Give gravity to multiple characters?

PostPosted: Wed Feb 02, 2011 7:55 pm
by ThaKid244
Code: Select all
char * key = GetKeyState();

if (key[KEY_LEFT]==1 && key[KEY_UP]==0 && key[KEY_RIGHT]==0 && key[KEY_DOWN]==0)
{
    x-=6;
    if (jump == 0)
    {
        ChangeAnimation("MIchael", "mRunL_001", NO_CHANGE);
    }
 
    if (jump == 1)
    {
        ChangeAnimation("MIchael", "mJumpL_001", NO_CHANGE);
    }
}

else if (key[KEY_LEFT]==0 && key[KEY_UP]==1 && key[KEY_RIGHT]==0 && key[KEY_DOWN]==0)
{
    ChangeAnimation("MIchael", "mJumpR_001", NO_CHANGE);
    if (jump == 0)
    {
        yvelocity=-14;
        jump=1;
    }
}
 
else if (key[KEY_LEFT]==0 && key[KEY_UP]==0 && key[KEY_RIGHT]==1 && key[KEY_DOWN]==0)
{
    x+=6;
    if (jump == 0)
    {
        ChangeAnimation("MIchael", "mRunR_001", NO_CHANGE);
    }
    if (jump == 1)
    {
        ChangeAnimation("MIchael", "mJumpR_001", NO_CHANGE);
    }
}

else if (key[KEY_LEFT]==0 && key[KEY_UP]==0 && key[KEY_RIGHT]==0 && key[KEY_DOWN]==1)
{
}

else if (key[KEY_LEFT]==1 && key[KEY_UP]==1 && key[KEY_RIGHT]==0 && key[KEY_DOWN]==0)
{
    x-=6;
    ChangeAnimation("MIchael", "mJumpL_001", NO_CHANGE);
    if (jump == 0)
    {
        yvelocity=-14;
        jump=1;
    }
}

else if (key[KEY_LEFT]==1 && key[KEY_UP]==1 && key[KEY_RIGHT]==1 && key[KEY_DOWN]==0)
{
}

else if (key[KEY_LEFT]==1 && key[KEY_UP]==1 && key[KEY_RIGHT]==0 && key[KEY_DOWN]==1)
{
    if (jump == 0)
    {
        yvelocity=-14;
        jump=1;
    }
}

else if (key[KEY_LEFT]==1 && key[KEY_UP]==1 && key[KEY_RIGHT]==1 && key[KEY_DOWN]==1)
{
    x=x;
    ChangeAnimation("MIchael", "mStandL_001", NO_CHANGE);
}

else if (key[KEY_LEFT]==1 && key[KEY_UP]==0 && key[KEY_RIGHT]==1 && key[KEY_DOWN]==0)
{
    x=x;
    ChangeAnimation("MIchael", "mStandR_001", NO_CHANGE);
}

else if (key[KEY_LEFT]==1 && key[KEY_UP]==0 && key[KEY_RIGHT]==1 && key[KEY_DOWN]==1)
{
    ChangeAnimation("MIchael", "mStandR_001", NO_CHANGE);
}
 
else if (key[KEY_LEFT]==1 && key[KEY_UP]==0 && key[KEY_RIGHT]==0 && key[KEY_DOWN]==1)
{
    x-=6;
    ChangeAnimation("MIchael", "mRunL_001", NO_CHANGE);
}

else if (key[KEY_LEFT]==0 && key[KEY_UP]==1 && key[KEY_RIGHT]==1 && key[KEY_DOWN]==0)
{
    x+=6;
    ChangeAnimation("MIchael", "mJumpR_001", NO_CHANGE);
    if (jump == 0)
    {
        yvelocity=-14;
        jump=1;
    }
}

else if (key[KEY_LEFT]==0 && key[KEY_UP]==1 && key[KEY_RIGHT]==1 && key[KEY_DOWN]==1)
{
    x=x;
    ChangeAnimation("MIchael", "mStandR_001", NO_CHANGE);
}

else if (key[KEY_LEFT]==0 && key[KEY_UP]==1 && key[KEY_RIGHT]==0 && key[KEY_DOWN]==1)
{
    x=x;
    ChangeAnimation("MIchael", "mStandR_001", NO_CHANGE);
}

else if (key[KEY_LEFT]==0 && key[KEY_UP]==0 && key[KEY_RIGHT]==1 && key[KEY_DOWN]==1)
{
    x+=6;
    ChangeAnimation("MIchael", "mRunR_001", NO_CHANGE);
}


&&

Code: Select all
if (yvelocity<4)
{
    yvelocity+=.08;
}


if (yvelocity>=1)
{
    jump=1;
}


if (yvelocity<1.5)
{
    yvelocity-=.1;
}


if (yvelocity<-.8)
{
    yvelocity-=.2;
}


yvelocity++;

Re: Give gravity to multiple characters?

PostPosted: Fri Feb 04, 2011 11:07 am
by Game A Gogo
Gravity reacts equally on every object, but what makes some object fall faster than other? A rock falls faster than a paper, agreed?

There are two variables to this, Mass and Aero-dynamic. A rock has more mass, thus more particle is attracted towards the center of the earth, so it will take more to stop this one's movement and on top of that, it is quite aero-dynamic (Depends on a rock... think of a round one). While a peice of paper is barely massive at all, it takes less energy to stop the paper from moving, and it's aero-dynamic is rather poor, considering the paper tends to move more horizontally.

So how do we replicate this in our game???
Easy enough! You keep the same gravity, but you limit it! heres an easy way:
Code: Select all
yvelocity=min(4,yvelocity+1);//instead of yvelocity++

this will limit yvelocity to 4.

Hope this helps!