Sign in to follow this  

how do u get an original position of an object?

This topic is 4095 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

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
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
Is the game world all of the same height? If so just store the ground height as groundlevel = 50 or something. If your game world consists of a variety of heights, then if your charector always reverted back to the original y value, how would he jump up platforms?

To make a very simple way of storing your game world try an array the size of the world in pixels, where the value of the array is the ground level at that point. But without more information on your style of game we can't do much else. Good luck.

Share this post


Link to post
Share on other sites
One approach could be to consider the ground at Y=0, and when your player jumps up in the air, give them a negative position.

If then on the screen your ground is actually at, say 200, you would convert the player Y to screen co-ords by doing Player.Y+200 before drawing.

Then, when falling, you just increment the player Y until it is equal to zero again.

This would involve anchoring your sprites at their base rather than top left, but that is probably a good idea for a Double Dragon style game anyway.

It was suggested (by someone else) to you in a previous thread that, due to the style of game you are writing, you should consider having a Z component to represent how far up or down the ground the player is, and a Y component to represent how far above the ground it is. I still think this would be the best option for the type of view your game seems to have.

Share this post


Link to post
Share on other sites

This topic is 4095 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this