Custom assets

3D models client-side

Tags: asset, custom

TIP

Currently only .obj and .gltf are supported for 3d models

You can import and manage 3d models inside of krunker using KrunkScript.

# Add an asset to the scene.
GAME.SCENE.addAsset(
    "236t",         # str 3d asset id
    5,              # num x position
    0,              # num y position
    5,              # num z position
    1,              # num scale
    "#FFF",         # str color
    {},             # obj additional data
    onObjectLoad    # action callback when asset loads. (function name is function used for callback)
);
1
2
3
4
5
6
7
8
9
10
11

Textures & images client-side

TIP

Currently only .png images are supported

# Create an object reference and change its texture id.
obj cube = GAME.SCENE.addCube("", "#fff", 0, 0, 0, 10, 10, 10);
cube.texture = "28000";
1
2
3

Animations client-side

Default animations client-side

Tags: clips

The krunker playermodels has some player animations by default.

  • Idle: Loops while player is idle
  • Move: Loops while player is moving
  • Crouch: Loops while player is crouched
  • Jump: Plays when player jumps
  • Melee: Plays when player melees
  • Shoot: Plays when player shoots

Custom animations client-side

TIP

Only gltf's support animations

# Create a 3d asset object
obj object = GAME.SCENE.addAsset("11441g", 0, 0, 0, 1);

# Play animation on object
object.playAnim(
	"Jump",             # str clip name
	1                   # num repetitions (0 = infinite loop)
);

# You can also do this on players and AI
player.playAnim("Jump");
aiBot.playAnim("Jump");

# Stop object animation
object.stopAnim();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# Playing an animation thru GAME method
obj object = GAME.SCENE.addAsset("11441g", 0, 0, 0, 1);

# Play animation
GAME.ANIM.playClip(object, "Jump", 0);

# Stop animation
GAME.ANIM.stopClip(object, "Jump");
1
2
3
4
5
6
7
8

Sounds & music client-side

Tags: audio

TIP

The sound asset id parameter will automatically convert str's to num's as of update 5.5.0

# Play sound in 2D space
obj sound = GAME.SOUND.play2D(
    0,      # num sound asset id
    1,      # num volume (0 - 1)
    1,      # num rate (0 - 1)
    true    # bool looping
);
1
2
3
4
5
6
7
# Play sound in 3D space
obj sound = GAME.SOUND.play3D(
    37204,  # num sound asset id
    1,      # num volume (0 - 1) 
    5,      # num x position
    0,      # num y position
    5,      # num z position
    0.9,    # num rate (0 - 1)
    true    # bool looping
);
1
2
3
4
5
6
7
8
9
10
# Alter rate & volume
sound.rate = 0.5;
sound.volume = 0.2;

# Mute, unmute, play, stop & pause
sound.mute();
sound.unmute();
sound.play();
sound.stop();
sound.pause();

# Fade
sound.fade(
    0.9,    # num volume start (0 - 1)
    0.1,    # num volume end (0 - 1)
    0       # num duration
);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17