Give gravity to multiple characters?

Non-platform specific questions.

Give gravity to multiple characters?

Postby ThaKid244 » Wed Feb 02, 2011 3:04 pm

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
K Thanks! ;)
User avatar
ThaKid244
 
Posts: 34
Joined: Thu Dec 23, 2010 6:40 pm
Score: 0 Give a positive score

Re: Give gravity to multiple characters?

Postby Hblade » Wed Feb 02, 2011 4:31 pm

Whats the code for the one thats heavy?
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Give gravity to multiple characters?

Postby ThaKid244 » Wed Feb 02, 2011 7:55 pm

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++;
K Thanks! ;)
User avatar
ThaKid244
 
Posts: 34
Joined: Thu Dec 23, 2010 6:40 pm
Score: 0 Give a positive score

Re: Give gravity to multiple characters?

Postby Game A Gogo » Fri Feb 04, 2011 11:07 am

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!
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest