• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
P0jahn

Tutorial for making a side-scrolling gravity character

7 posts in this topic

I want to create a character for my game that is similar to Meatboy(or just Super Mario Bros if you are not familiar with Meatboy).

That is, a character that can jump, and fall after a while, a character that can do walljumps and wallslide, a character that will fall when "he" walk on a cliff(hollow space) and all that stuff. This seems like a very difficult challenge. I have been searching for a tutorial but I cant find anything.

 

Anyone have any ideas?

0

Share this post


Link to post
Share on other sites

How familiar are you with Newtonian physics? (Specifically the nature of force and inertia.)

 

Apart from basic physics it's just a matter of good collision detection.

 

Someone linked to this recently:

 

http://www.gamedev.net/page/resources/_/technical/game-programming/the-guide-to-implementing-2d-platformers-r2936

 

I found it to be a good article.

Edited by Khatharr
1

Share this post


Link to post
Share on other sites

Bumping this.

For the past week I have been trying to implements gravity into my game.

I have read a lot of tutorials, but none of them are really suitable for my game.

Its not the actual jumping algorithm I have trouble with, its the other features. Well, the jumping algorithm is messy too.


The features I want:

1. When pressing the jump button, do not jump to the maximum height immediately. Instead, you have to hold the jump button to jump higher(and respect a limit). This feature would allow short-jumps and give you more control over your character.

 

2. Activate gravity if you walked down from a cliff for example(i e, you are in the air without have jumped).

(Detecting whether or not I am in air is not a problem, but where to put the code is).

 

3. After you released your jump button, you can not jump again until you hit the ground.

 

None of these are not really hard to implement, but combining all these function is hard.

 

Like any other 2D game, the top-left corner of the screen have coordinates 0,0, and both increases when moving right/down.

I have created a bit of code but it needs to be rewritten for the tenth time.
I will show it tomorrow, but until then, I hope to get some ideas.

0

Share this post


Link to post
Share on other sites

Instead of looking for a tutorial that matches your exact requirements, you can gain a lot more by solving this yourself.

 

1. When pressing the jump button, do not jump to the maximum height immediately. Instead, you have to hold the jump button to jump higher(and respect a limit). This feature would allow short-jumps and give you more control over your character.

 

How do you think this could be achieved? If you know the maximum jump height and specify a jump speed, you can increment the characters height by the speed until they've reached the height limit - whilst the jump button is pressed. And when the jump button is released, the player falls. Once you've done this, you could improve the "feel" of the jump, by changing the characters jump height to increase by smaller and smaller amounts over time - rather than a constant speed. This will create a slightly floaty/hovery jump depending on the curve/falloff.

 

 2. Activate gravity if you walked down from a cliff for example(i e, you are in the air without have jumped).

(Detecting whether or not I am in air is not a problem, but where to put the code is).

 

So you know the solution to the problem, but don't know where to put the code? You could place this code just after the input if you'd like.

(Though I'd suggest you place the physics code in the same area)
 

 3. After you released your jump button, you can not jump again until you hit the ground.

 

You know when the jump button has been released, so you'll need to know when you've hit the ground. If you're using tiles/grid, check the tile below you is a floor/ground tile. If you're touching this tile, you've hit the ground. Reset the jump ability here.

 

 None of these are not really hard to implement, but combining all these function is hard.

 

At this stage, solve the problems one at a time. 

 

Additionally, I'd like to add that it took a long time for them to get the movement mechanics right, with lots of tweaking. You would probably benefit from making a simpler jump system first, and then improving that once it's complete.

 

 

 I will show it tomorrow, but until then, I hope to get some ideas.


Looking forward to it smile.png

0

Share this post


Link to post
Share on other sites

Vector2 position(0.0, 0.0);
Vector2 velocity(0.0, 0.0);
Vector2 force(0.0, 0.0);
float mass = 1.0;
float gravity = -9.8;
float damping = 0.001f;

while(true)
{
    float dt = 0.016;//time elapse per frame in seconds

    //Do game logic here

    position = position + velocity * dt;

    //adds fake friction
    velocity *= 1.0 - (damping * dt);

    //adds gravity based on mass
    force.y += mass * gravity;

    velocity = velocity + (force / mass) * dt;
    force = 0;
}

 
1. When pressing the jump button, do not jump to the maximum height immediately. Instead, you have to hold the jump button to jump higher(and respect a limit). This feature would allow short-jumps and give you more control over your character.

To the algorithm above, add some value to force.y once. If you hold down a key then continue to add a force over multiple frames. 

 

 
2. Activate gravity if you walked down from a cliff for example(i e, you are in the air without have jumped)

The algorithm above with handle this automatically with gravity. Change the gravity value to increase the acceleration.

 

 
3. After you released your jump button, you can not jump again until you hit the ground.

For this you'll need to add collision detection and response, and may get tricky. 

Edited by Nyssa
0

Share this post


Link to post
Share on other sites

I wasn't joking about physics. Gravity and jumping force can very easily be handled as classical Newtonian forces.

If you understand the terms 'force', 'acceleration', 'velocity', 'terminal velocity', 'speed' and 'momentum' in the sense that they are used in physics then this should be very easy to implement.

If you don't know them in the scientific sense then spend a few hours getting to understand those concepts well, especially the relationship between force, acceleration and speed. Once you understand those concepts you can apply them directly to this kind of physics.

The only queer thing about jumping force is that the application of the force is dependent on whether the button is still pressed. When I did platformers I would have a 'jump_potential' variable that specified the amount of jumping force available. When the jump button was pressed then each frame I'd apply a set fraction of the jump_potential to the character as an upward force. (You can avoid asymptotic behavior in this case by simply using integer division.) If the button was released then the jump_potential would be emptied. If the character was standing on something (and the button was not pressed) then the jump_potential would be reset to its start value.

0

Share this post


Link to post
Share on other sites

An update, it is going pretty well this time. I am using a modified version of Nyssas code.

I have a problem thought, with slopes.

When I run down from a cliff, the gravity work as expected, it pulls me down until I hit the ground.

But when I move down from a slope, I dont want to use the gravity/pushdown effect. Instead I just want to move the character down manually(increasing its y variable). Right now, when I move down from a slope, the character is not touching the slope, he just fly over it.

 

To solve this, I could just set the gravity to a very high value when I am standing on the slopes, but how do I detect that?
My map is a 2D char array, where 0 is solid and 1 is hollow.

0

Share this post


Link to post
Share on other sites

Since you're using a char array it shouldn't take too much to detect if a slope is coming:

 

int tilePositionX, tilePositionY;
char tileArray[mapSizeX][mapSizeY];

int nextXTile = tilePositionX+1;//+1 assuming you are moving forward
int yTileBelow = tilePositionY+1;

if ((nextXTile < mapSizeX) && (yTileBelow < mapSizeY))
{
    //where 0 is solid and 1 is hollow
    if (tileArray[nextXTile][yTileBelow]) == 1)
    {
        //the next tile is on a slope or there is a hole
    }
}
Edited by Nyssa
0

Share this post


Link to post
Share on other sites

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  
Followers 0