3 Replies - 1037 Views - Last Post: 05 May 2016 - 03:47 PM

#1 football1994  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 30
  • Joined: 01-July 13

Mid air double jump 3d

Posted 05 May 2016 - 11:51 AM

HI everyone

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
Attached Image

Is This A Good Question/Topic? 0
  • +

Replies To: Mid air double jump 3d

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13392
  • View blog
  • Posts: 53,445
  • Joined: 12-June 08

Re: Mid air double jump 3d

Posted 05 May 2016 - 11:53 AM

What's the question?
Was This Post Helpful? 0
  • +
  • -

#3 football1994  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 30
  • Joined: 01-July 13

Re: Mid air double jump 3d

Posted 05 May 2016 - 01:09 PM

Thanks for responding modi123_1,the avatar can only jump from height 0 what I
want to do is to implement the ability to jump again during the original (gravityVelocity = 1f;) jump.
the latest and smallest method Ive tried among others is:

if(gravityVelocity <= 1f)
{
if (keyState.IsKeyDown(Keys.L))
{
gravityVelocity = 1f;
}

}

Ive tried translating 2d versions of the mid air jump method which used much more code than the previous example but still no luck. my question would be how do I give the avatar the ability to jump from a height other than zero.






this is the code Ive changed many times to implement a mid air jump
 //jump 
20
	                if (keyState.IsKeyDown(Keys.L))
21
	                {
22
	                    gravityVelocity = 1f;       // Adjust this value to control height of jump. 
23
	                }






Thanks again :)/>/>
Was This Post Helpful? 0
  • +
  • -

#4 basteagui  Icon User is offline

  • D.I.C Head

Reputation: 14
  • View blog
  • Posts: 60
  • Joined: 08-September 13

Re: Mid air double jump 3d

Posted 05 May 2016 - 03:47 PM

implement an INTEGER that represents a number of action your player is doing;
if he is walking, then make something like INT ACTION: 0 //walking.

so if action 1 is jumping, you make it so that

if (keyState.IsKeyDown(Keys.L))
{
SET ACTION TO JUMP!
}
if (ACTION == JUMP)
{
Velocity -= 20; //if jump is over then switch action to FALLING, another number of your INT.
}


and then you can easily make it so if L is pressed and action is already jump then you can set the velocity to -20 in the Y direction again


this way of representing actions by number is called a finite state machine, and it will help you make sense of what your program looks for each frame. if your program is only listening for a double jump input on jump action then theres a lot less checks to do if player is on the ground and what can he do now, etc. i hope this makes sense

This post has been edited by basteagui: 05 May 2016 - 03:49 PM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1