basic-move-and-dodge-game

[LEARNING] basic godot game based off the tutorial by borncg on youtube
git clone git://git.figbert.com/basic-move-and-dodge-game.git
Log | Files | Refs | README

Character.gd (770B)


      1 extends KinematicBody
      2 
      3 const acceleration: float = 0.1
      4 var velocity = Vector3.DOWN * 12
      5 var speed: float = 15
      6 
      7 func _ready():
      8 	pass
      9 
     10 func _physics_process(delta):
     11 	var strength = Vector2(
     12 		Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left"),
     13 		Input.get_action_strength("ui_down") - Input.get_action_strength("ui_up")
     14 	).normalized() * speed
     15 	
     16 	var motion = Vector2(
     17 		lerp(velocity.x, strength.x, acceleration),
     18 		lerp(velocity.z, strength.y, acceleration)
     19 	)
     20 	
     21 	velocity.x = motion.x
     22 	velocity.z = motion.y
     23 	$MeshInstance.rotate_z(deg2rad(-velocity.x))
     24 	$MeshInstance.rotate_x(deg2rad(velocity.z))
     25 	
     26 	move_and_slide(velocity)
     27 
     28 
     29 func _on_enemy_body_entered(body):
     30 	if body.name == "Character":
     31 		get_tree().change_scene("res://GameOver.tscn")