Advertisement
Guest User

Untitled

a guest
Jan 28th, 2023
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. extends Node2D
  2.  
  3. @onready var map = $TileMap
  4. @onready var player = $CharacterBody2D
  5. @onready var cam = $Camera2D
  6. const rotation_speed = 1.5
  7. var desired_rotation
  8.  
  9. # Called when the node enters the scene tree for the first time.
  10. func _ready():
  11.     desired_rotation = player.global_rotation
  12.  
  13.  
  14. # Called every frame. 'delta' is the elapsed time since the previous frame.
  15. func _process(delta):
  16.     move_camera()
  17.    
  18.     if Input.is_action_just_pressed("activate_flip"):
  19.         player.process_mode = Node.PROCESS_MODE_DISABLED
  20.         desired_rotation = desired_rotation + PI
  21.        
  22.     # Rotate the player towards desired orientation
  23.     if desired_rotation - player.global_rotation > 0.1:
  24.         player.global_rotation += 1 * rotation_speed * delta
  25.     else:
  26.         # Close enough, snap to the en
  27.         player.global_rotation = desired_rotation
  28.         desired_rotation = player.global_rotation
  29.         if player.process_mode == Node.PROCESS_MODE_DISABLED:
  30.             var diff = player.position - map.position
  31.             map.position += diff * 2
  32.             player.process_mode = Node.PROCESS_MODE_ALWAYS
  33.        
  34.  
  35. func move_camera():
  36.     cam.position = lerp(cam.position, player.position, 0.1).round()
  37.     cam.rotation = player.rotation
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement