•      Sign In
• Create Account

### #ActualNyssa

Posted 28 January 2013 - 08:59 PM


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.

### #3Nyssa

Posted 28 January 2013 - 07:23 PM


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 - f = ma
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.

### #2Nyssa

Posted 28 January 2013 - 07:08 PM


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;

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

//Do game logic here

position = position + velocity * dt;

//adds gravity - f = ma
force.y += mass * gravity;

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


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.

### #1Nyssa

Posted 28 January 2013 - 07:04 PM


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;

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

//Do game logic here

position = position + velocity * dt;

//adds gravity - f = ma
force.y += mass * gravity;

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


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.

PARTNERS