Jump to content

View more

Image of the Day

Adding some finishing touches...
Follow us for more
#screenshotsaturday #indiedev... by #MakeGoodGames https://t.co/Otbwywbm3a
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Player animation going funny.

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
1 reply to this topic

#1 andfol   Members   

103
Like
0Likes
Like

Posted 14 March 2012 - 05:13 AM

Hi,

I have a player drawn in OpenGL with animation on it to make the legs and arms move. I have two arrays in the body of my constructor to keep track of movement:

float armAngle[2] = {0.0f, 0.0f};
float legAngle[2] = {0.0f, 0.0f};

I draw a cube in OpenGL and call this function to draw the player arms, legs etc also using color, translate and scale.

The drawPlayer function then draws and animates the player:

void CPlayer::drawPlayer()
{
static bool leg1 = true; // robot's leg states
static bool leg2 = false; // true = forward, false = back

static bool arm1 = true;
static bool arm2 = false;

glPushMatrix();

glTranslatef(m_xPos, m_yPos, m_zPos);// draw robot at desired coordinates



// draw components
drawHead(1.0f, 2.0f, 0.0f);
drawTorso(1.5f, 0.0f, 0.0f);

glPushMatrix();
// if leg is moving forward, increase angle, else decrease angle
if (arm1)
armAngle[0] = armAngle[0] + 0.1f;
else
armAngle[0] = armAngle[0] - 0.1f;

// once leg has reached its maximum angle in a direction,
// reverse it
if (armAngle[0] >= 15.0f)
arm1 = false;
if (armAngle[0] <= -15.0f)
arm1 = true;

// move the leg away from the torso and rotate it to give "walking" effect
glTranslatef(0.0f, -0.5f, 0.0f);
glRotatef(armAngle[0], 1.0f, 0.0f, 0.0f);
drawArm(3.5f, 0.0f, -0.5f);
glPopMatrix();

glPushMatrix();
// if leg is moving forward, increase angle, else decrease angle
if (arm2)
armAngle[1] = armAngle[1] + 0.1f;
else
armAngle[1] = armAngle[1] - 0.1f;

// once leg has reached its maximum angle in a direction,
// reverse it
if (armAngle[1] >= 15.0f)
arm2 = false;
if (armAngle[1] <= -15.0f)
arm2 = true;

// move the leg away from the torso and rotate it to give "walking" effect
glTranslatef(0.0f, -0.5f, 0.0f);
glRotatef(armAngle[1], 1.0f, 0.0f, 0.0f);
drawArm(-2.5f, 0.0f, -0.5f);
glPopMatrix();

//DrawArm(-1.5f, 0.0f, -0.5f);

// we want to rotate the legs relative to the robot's position in the world
// this is leg 1, the robot's right leg
glPushMatrix();

// if leg is moving forward, increase angle, else decrease angle
if (leg1)
legAngle[0] = legAngle[0] + 0.1f;
else
legAngle[0] = legAngle[0] - 0.1f;

// once leg has reached its maximum angle in a direction,
// reverse it
if (legAngle[0] >= 15.0f)
leg1 = false;
if (legAngle[0] <= -15.0f)
leg1 = true;

// move the leg away from the torso and rotate it to give "walking" effect
glTranslatef(0.0f, -0.5f, 0.0f);
glRotatef(legAngle[0], 1.0f, 0.0f, 0.0f);

// draw the leg
drawLeg(-0.5f, -5.0f, -0.5f);

glPopMatrix();

// do the same as above with leg 2, the robot's left leg
glPushMatrix();

if (leg2)
legAngle[1] = legAngle[1] + 0.1f;
else
legAngle[1] = legAngle[1] - 0.1f;

if (legAngle[1] >= 15.0f)
leg2 = false;
if (legAngle[1] <= -15.0f)
leg2 = true;

glTranslatef(0.0f, -0.5f, 0.0f);
glRotatef(legAngle[1], 1.0f, 0.0f, 0.0f);
drawLeg(1.5f, -5.0f, -0.5f);
glPopMatrix();
glPopMatrix();
}

This player also has movement on it using GetKeyState called in main.

if(GetKeyState(VK_UP) & 0x80)
{
g_Player1.move(0.0, 0.05, 0.0);
}

The problem is that after moving the player around the screen after a while the arms and legs on the player keep animating round in a full circle rather than the short steps they are supposed to take. I would be grateful for some help with this.

#2 andfol   Members   

103
Like
0Likes
Like

Posted 20 March 2012 - 02:53 PM

This bug is now fixed.




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.