• Advertisement
Sign in to follow this  

Quick help on this function?

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

Hi basically what i am trying to achieve is to get the current player in the air, so i can move the world camera up or down. I wrote a method that gets the current player in the air but it seems if i have 2 players if player 2 jumps first and then player 1 jumps it tries to follow player 1. But if player 1 jumps first then player 2 it works fine as it follows player 1 first and not player 2. here is my method

Centity *CCameraManager::GetPlayerToFollow()
{
	CEntity *player=NULL;
	bool inAirAlready=false;
	
	//Only one person in the list? Then follow the this one.
	if(m_PlayerNPCList.size()==1)
	{
		player=m_PlayerNPCList.at(0);
	}
	else
	{
		foreach(Centity *entity, m_PlayerNPCList)
		{
			if(entity&&!inAirAlready)
			{
				if(entity->InAir())
				{
					player=entity;
					inAirAlready=true;
				}
			}
		}
	}
	
	return player;
}



It seems if player 2 jumps first then player 1 jumps it then tries to follow player 1 when it should wait until player 2 finishes first?

Share this post


Link to post
Share on other sites
Advertisement
The problem is that your function has no knowledge of who jumped first. It simply searches the list of players and returns the first player in the list who is in the air. If player 1 is in the air then it will always return player 1, as it will check to see if player 1 is in the air before it checks player 2. The inAirAlready boolean is preventing it from ever considering player 2 if player 1 is in the air.

In order to solve the problem you will need to create some sort of time based order in which the players began being in the air. This could take the form of recording the time that the player jumped, and then searching the player list for the earliest time. It could also take the form of having another list that is sorted in the order in which the player jumped. This would involve adding a player to the back of the list when he jumps, and removing players who are no longer jumping from the list. As long as you always add new jumpers to the back of the list, then it will always be sorted from front to back in the order that the players jumped.

Share this post


Link to post
Share on other sites
thanks mate i think i will take the second approach as i was doing something like that earlier. I am making a scrolling beat em up engine been a long time on and off would love to show something to you guys soon.

Share this post


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

  • Advertisement