Skip to content

Commit 5d70c47

Browse files
committed
Add player ability to double jump
1 parent 738f5d0 commit 5d70c47

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

public/scripts.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ scene.add( plane );
5252

5353
scene.background = new THREE.Color( 0x99ffff );
5454

55-
var jumping = false;
55+
var jumping = doublejumping = false;
5656
var jump_distance = 0.1;
5757
var acceleration = 0.0025;
5858
var acceleration_step = 0.0025;
@@ -97,10 +97,16 @@ var animate = function () {
9797
}
9898

9999
if (keyboard.pressed("space")) {
100+
if (jumping && ! doublejumping && jump_distance < 0.07) {
101+
jump_distance = 0.1;
102+
acceleration_step = acceleration;
103+
doublejumping = true;
104+
}
105+
100106
jumping = true;
101107
}
102108

103-
if (jumping) {
109+
if (jumping || doublejumping) {
104110
acceleration_step = acceleration_step * (1 + acceleration);
105111

106112
jump_distance -= acceleration_step;
@@ -109,7 +115,7 @@ var animate = function () {
109115
}
110116

111117
if (player.position.y < initial_y) { // hit the "ground"
112-
jumping = false;
118+
jumping = doublejumping = false;
113119

114120
// reset our acceleration calculations
115121
jump_distance = 0.1;

0 commit comments

Comments
 (0)