Ive been experimenting with gravity in my project and with much input from others Ive managed to

add a jumping element, and now I'm working on implementing a mid air double jump to the method but so

far Ive run into many brick walls trying to do so, and was hoping if anyone had any suggestions as to

how to go about doing it.

Thankyou

The Methods I used are below

The jump method

void DudeGravity2(GameTime gameTime) { float treshold = 0.0f; float terrainHeight = GetExactHeightAt(avatarPosition2.X, -avatarPosition2.Z); if (avatarPosition2.Y < terrainHeight + treshold) { newPos = avatarPosition2; newPos.Y = terrainHeight + treshold * (float)gameTime.ElapsedGameTime.TotalSeconds; avatarPosition2 = newPos; gravityVelocity = 0;// On ground so not falling. //jump if (keyState.IsKeyDown(Keys.L)) { gravityVelocity = 1f; // Adjust this value to control height of jump. } } else { // Not on ground so must be falling. //Add in effect of gravity on current velocity. // m/sec^2 float g = -1.10f; gravityVelocity += g * (float)gameTime.ElapsedGameTime.TotalSeconds; //Add effect of velocity to position. newPos = avatarPosition2; newPos.Y += gravityVelocity * (float)gameTime.ElapsedGameTime.TotalSeconds; avatarPosition2 = newPos; }

The method I used to get the height of the terrain

(GetExactHeightAt)

public float GetExactHeightAt(float xCoord, float zCoord) { bool invalid = xCoord < 0; invalid |= zCoord < 0; invalid |= xCoord > floorPlan.GetLength(0) - 1; invalid |= zCoord > floorPlan.GetLength(1) - 1; if (invalid) return 10; int xLower = (int)xCoord; int xHigher = xLower + 1; float xRelative = (xCoord - xLower) / ((float)xHigher - (float)xLower); int zLower = (int)zCoord; int zHigher = zLower + 1; float zRelative = (zCoord - zLower) / ((float)zHigher - (float)zLower); float heightLxLz = floorPlan[xLower, zLower]; float heightLxHz = floorPlan[xLower, zHigher]; float heightHxLz = floorPlan[xHigher, zLower]; float heightHxHz = floorPlan[xHigher, zHigher]; bool cameraAboveLowerTriangle = (xRelative + zRelative < 1); float finalHeight; if (cameraAboveLowerTriangle) { finalHeight = heightLxLz; finalHeight += zRelative * (heightLxHz - heightLxLz); finalHeight += xRelative * (heightHxLz - heightLxLz); } else { finalHeight = heightHxHz; finalHeight += (1.0f - zRelative) * (heightHxLz - heightHxHz); finalHeight += (1.0f - xRelative) * (heightLxHz - heightHxHz); } return finalHeight; }

The terrain I used is from riemers flightsim tutorial(link below)

http://www.riemers.n...e_floorplan.php

Visual illustrations of what Im trying to implement

(Mario does a mid air double jump at about 21 seconds into the video)

https://www.youtube....h?v=C9J9HxwUnuA

here's a 2d version of the midair double jump

https://www.youtube....h?v=qev4gzqbnQs

here's a 2d jpeg illustration. The character does a mid air jump avoiding the water