Double jump script example

# Add this both on the server and client side.

public action onPlayerSpawn(str id) {
	obj player = GAME.PLAYERS.findByID(id);
	player.doubleJump = false;
	player.singleJump = false;
	player.hasSingleJumped = false;

	player.registerSyncValues("singleJump");
	player.registerSyncValues("hasSingleJumped");
	player.registerSyncValues("doubleJump");
}

public action onPlayerUpdate(str id, num delta, obj inputs) {
	obj player = GAME.PLAYERS.findByID(id);
	
	if ((bool) inputs.jump){
		#Single jump
		if (!(bool) player.singleJump) {
			player.singleJump = true;
		}
		
		#Double jump
		if ((bool) player.hasSingleJumped && !(bool) player.doubleJump) {
			player.velocity.y = 0.082;
			player.doubleJump = true;
		}
	}
	else {
		if ((bool) player.onGround) {
			player.doubleJump = false;
			player.singleJump = false;
			player.hasSingleJumped = false;
		}
		
		if ((bool) player.singleJump) {
			player.hasSingleJumped = true;
		}
	}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40