diff options
author | Victor Andrade de Almeida <vct.a.almeida@gmail.com> | 2022-07-16 00:27:02 -0300 |
---|---|---|
committer | Victor Andrade de Almeida <vct.a.almeida@gmail.com> | 2022-07-16 00:27:13 -0300 |
commit | d415ef0ed7bcab15f41e03083cb286b03870b414 (patch) | |
tree | 57f905872ef5d082bbc2ef00e2aa43fa9624d514 | |
parent | ef33112d4c103b8d7ff7fb7a5773bf31075eb131 (diff) | |
download | gamejam-gmtk-2022-d415ef0ed7bcab15f41e03083cb286b03870b414.tar.gz gamejam-gmtk-2022-d415ef0ed7bcab15f41e03083cb286b03870b414.tar.bz2 gamejam-gmtk-2022-d415ef0ed7bcab15f41e03083cb286b03870b414.zip |
add collision shake
-rw-r--r-- | Scenes/Dungeon.gd | 3 | ||||
-rw-r--r-- | Scenes/Player.gd | 22 |
2 files changed, 22 insertions, 3 deletions
diff --git a/Scenes/Dungeon.gd b/Scenes/Dungeon.gd index 76e7f52..0d5ced5 100644 --- a/Scenes/Dungeon.gd +++ b/Scenes/Dungeon.gd @@ -99,6 +99,7 @@ func move_player(dir : Vector2): var new_tile = cur_tile + dir if tiles_entities.has(new_tile): + player.add_action("cor_shake", [0.2]) return tiles_entities.erase(cur_tile) @@ -106,7 +107,7 @@ func move_player(dir : Vector2): #player_check_attack(new_tile) - player.add_action("cor_move", [tile_to_pos(new_tile)]) + player.add_action("cor_move", [tile_to_pos(new_tile), 0.2]) player.roll(dir) func tile_to_pos(tile : Vector2): diff --git a/Scenes/Player.gd b/Scenes/Player.gd index b94afa6..145af4f 100644 --- a/Scenes/Player.gd +++ b/Scenes/Player.gd @@ -65,7 +65,7 @@ func get_cardinal(direction: Vector2): func get_upper_face(): return get_top() -func cor_move(args : Array): # args = [Vector3] +func cor_move(args : Array): # args = [Vector3, float] var pos_a = translation var pos_b = args[0] @@ -74,7 +74,7 @@ func cor_move(args : Array): # args = [Vector3] var basis_a = mesh.transform.basis var basis_b = basis_a.rotated(Vector3(dir.z, 0, -dir.x), PI / 2) - var duration = 0.2 + var duration = args[1] var time = 0 while true: @@ -89,3 +89,21 @@ func cor_move(args : Array): # args = [Vector3] break yield(get_tree(), "idle_frame") + +func cor_shake(args : Array): + var duration = args[0] + var time = 0 + + var zero = Vector3(0, 0.5, 0) + var intensity = 0.02 + + while true: + time = min(time + get_process_delta_time(), duration) + + mesh.translation = zero + (2 * Vector3(randf(), randf(), randf()) - Vector3.ONE) * intensity + + if time >= duration: + mesh.translation = zero + break + + yield(get_tree(), "idle_frame") |