Jump to content
  • Advertisement
Sign in to follow this  
lodoss118

how do u get an original position of an object?

This topic is 4382 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

say for example if i have a char that jumps and i want it to have the original y position before it jumped so i can know where the ground is?

Share this post


Link to post
Share on other sites
Advertisement
well yeah i done that but i have fall method aswell like when you get hit u fall back, so i was wondering how would i get the ground position for it? for the jump i know the ground becasue when i press jump i copy the the y position to another variable before it gets updated, but for fall i want to know an algorithm to get original y position?

Share this post


Link to post
Share on other sites
You would be better off to store the ground position explicitly, instead of calculating it. Then use collision detection to determine when to stop the player from falling.

Share this post


Link to post
Share on other sites



bool Character::isFall()
{
float speed = 5.4;

if(fall)
{
hEffect = true;
tempVelY -= 0.9; // Upseed
if(tempVelY <= -14) tempVelY = -14; //Downspeed
posy -= tempVelY;
if(faceDirX > 1)posx += (speed - weight);
if(faceDirX < -1)posx -= (speed - weight);
}

if(posy >= ground && fall)
{
fallCount++;
weight = 1.43;
tempVelY = (22 - 2.3);
}

if(fallCount >= bounces)
{
fall = false;
tempVelY = 22;
fallCount = 0;
weight = 0;
posy = ground;
hEffect = false;
alpha = 255;
hTimer = 0;
}

return fall;
}


Share this post


Link to post
Share on other sites
basically i need to find ground when fall is true, with jump i got the jump button to help out for finding the position but for fall i want to find out for itself?

Share this post


Link to post
Share on other sites
What you need to do is check to see if the players position is colliding with something in the world, if it is, you need to push them back to where they'd be sitting on top of the object that they collided with.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!