Advertisement
scolain

Godot 4 TDS Player move

Oct 27th, 2023 (edited)
1,057
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. extends CharacterBody2D
  2. class_name Player
  3.  
  4. signal player_died
  5.  
  6. @export var speed = 1000
  7. @export var acceleration = 0.1
  8. @export var friction = 0.05
  9.  
  10. var direction = Vector2()
  11.  
  12. # TODO : Ajouter timer au jeu
  13. var bullet_speed = 1000
  14. var bullet = preload("res://Bullet.tscn")
  15.  
  16. func _physics_process(_delta):
  17.     direction.x = Input.get_action_strength("right") - Input.get_action_strength("left")
  18.     direction.y = Input.get_action_strength("down") - Input.get_action_strength("up")
  19.    
  20.     direction = direction.normalized()
  21.    
  22.     #look_at(get_global_mouse_position())
  23.    
  24.     #if (Input.is_action_just_pressed("fire")):
  25.     #   fire()
  26.    
  27.     if (direction.length() > 0):
  28.         velocity = velocity.lerp(direction * speed, acceleration)
  29.     else :
  30.         velocity = velocity.lerp(Vector2.ZERO, friction)
  31.            
  32.     move_and_slide()
  33.  
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement