Game Development Community

Jumping Feature

by Nico Kelley · in Game Design and Creative Issues · 02/22/2012 (7:06 pm) · 5 replies

Hey, I'm new to this forum and I wasn't sure which area to post this in.

Anyway, Me and a few of my friends want to create a 2D platformer game for a small project and hopefully expand from that. Right now, my friends are working on sprites and such while I am working on getting some functionality. I was able to get some movement in using a few helpful tutorials and I was also able to add some collision (The ground). What I want to know is how to implement a sort of jump feature.

I had some ideas, but nothing seemed to work. I thought of using the update function in order to make it happen, but it didn't work out right. In one of my solutions, I was able to make my up arrow key cause different Y velocities, but I couldn't tap my key and make it "jump."

I would greatly appreciate a way to implement jumping or maybe just an idea how to do it. If my explanation wasn't clear I will try to reiterate a little.

I'm also sort of new to programming. I've done a little before but nothing too extreme, so you might lose me with some lingo.

Also, I'm using Torque2D Game Builder, if that helps at all.

About the author

Recent Threads


#1
02/23/2012 (2:05 pm)
I would highly recommend going through the platformer tutorial - when I was playing around with T2D it helped me get a prototype going in a matter of hours. If I remember right, the setVelocity() function was used for jumping. But don't take my word for it - it's all there in the tutorial!
#2
02/23/2012 (6:54 pm)
Thank you, I really appreciate your reply. And thanks for the link as well, I'll go through the tutorial tomorrow when I have time. If I'll come back with the results when I finish. Thanks again!
#3
02/24/2012 (9:08 am)
I'm not a 2D user, but I remember seeing this How to Make a Jump Function in TGB/iTGB/TGE Resource.
#4
02/24/2012 (12:49 pm)
http://www.rodedev.com/tutorials/gamephysics/

This explains it pretty well and it updates live so you can see what is going on.
#5
02/24/2012 (6:39 pm)
Hi everyone, Thanks for all of your replies, I tinkered around with it a little bit today. I was able to get some form of gravity to work with the jump. The only problem is, I have to keep pressing the key in order to shift the velocity. I set it so that when the "w" key is pressed, you get your upwards velocity, and then i have it set in the updateMovement function to subtract my gravity from my velocity.
I tried to set up a for-loop in order to get the gravity to constantly apply itself to the velocity, but I ended up going through the whole loop instantly. Is there a way to delay the loop or should I redirect my thinking to a different method?

function fishPlayer::updateMovement(%this)
{
if(%this.moveUp)
{
for(%count = 0; %count < 30; %count++)
{
%this.setLinearVelocityY( -$fishPlayer.vSpeedGrav );
$fishPlayer.vSpeedGrav -= $fishPlayer.gravity;
}
}
}

function fishPlayerUp()
{
if(!$fishPlayer.moveUp)
{
$fishPlayer.moveUp = true;
$fishPlayer.updateMovement();
}
}

PS. I don't know how to do code snippets, so sorry if it looks bad.