eskimo456 0 Junior Poster in Training

Hi there
I'm not to sure if this should go here or in games development so please move it if required.

I'm trying to make a basic function that allows my character to jump. The basic idea is to check if the character height is equal to that of the terrain map if it is then the character is not jumping. If its not then the character is jumping.

The jump will go up at a constant speed until it reaches a peak and then come down at the same speed for testing. The character however continuous infinitely and I have no idea why. If i print the y variable out for the player I get two different answers which I cant understand.

My jump function looks like this

double Robot::jumpFunction(double startHeight)

	static bool fallDown = false;
	static double newY;// = playerHeight;
	if(y < startHeight + 5.0 && fallDown == false)
		std::cout<<"y is "<<y<<std::endl;
		std::cout<<"start height is "<<startHeight<<std::endl;
		std::cout<<"start height +8 is " <<startHeight+8<<std::endl;
		newY += 0.2;


		fallDown = true;
		newY -= 0.2;

	return newY;

and i am calling it and using it like this

void Robot::drawRobot(PlayerControls &player,HeightMap *terrain, Weapon &playerWeapon)
	static bool jump;

	float rotationRadiens = myMath::DegreesToRadian(player.angle);
	robotX -= (sin(rotationRadiens) * player.speed); //used for forwards backward movement
	robotZ -= (cos(rotationRadiens) * player.speed);

	strafeRobotX += (cos(rotationRadiens) * player.strafe);  //used for strafing cos and sin as neccessary to match camera
	strafeRobotZ -= (sin(rotationRadiens) * player.strafe);

	x = robotX + strafeRobotX;
	z = robotZ + strafeRobotZ;

	if(y = terrain->getHeight(x,z)+(UPPER_LEG_LENGTH + LOWER_LEG_LENGTH))
		jump = false;

	if(jump == false && player.aPressed)
		y = jumpFunction(terrain->getHeight(x,z)+(UPPER_LEG_LENGTH + LOWER_LEG_LENGTH));
		//jump = true;

		y = terrain->getHeight(x,z)+(UPPER_LEG_LENGTH + LOWER_LEG_LENGTH);
	std::cout<<"y = "<<y<<std::endl;
	glTranslated(x,y,z); //translate by both the front back and side movement
	angle = player.angle-90;
	lookAngle = player.headAngle;

	//ThreeDModel model;

y is a public variable and is in the same class so shouldn't matter even if its private. I am printing y out in both locations and getting different results in the jump function it is equal to the height map(why it is always jumping) in the translate function it is the real value so += 200 or whatever. there is only one y variable so is there nay reason why it would be different in different functions in the same class?

Thanks for any help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.