Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends Node2D
- @onready var map = $TileMap
- @onready var player = $CharacterBody2D
- @onready var cam = $Camera2D
- const rotation_speed = 1.5
- var desired_rotation
- # Called when the node enters the scene tree for the first time.
- func _ready():
- desired_rotation = player.global_rotation
- # Called every frame. 'delta' is the elapsed time since the previous frame.
- func _process(delta):
- move_camera()
- if Input.is_action_just_pressed("activate_flip"):
- player.process_mode = Node.PROCESS_MODE_DISABLED
- desired_rotation = desired_rotation + PI
- # Rotate the player towards desired orientation
- if desired_rotation - player.global_rotation > 0.1:
- player.global_rotation += 1 * rotation_speed * delta
- else:
- # Close enough, snap to the en
- player.global_rotation = desired_rotation
- desired_rotation = player.global_rotation
- if player.process_mode == Node.PROCESS_MODE_DISABLED:
- var diff = player.position - map.position
- map.position += diff * 2
- player.process_mode = Node.PROCESS_MODE_ALWAYS
- func move_camera():
- cam.position = lerp(cam.position, player.position, 0.1).round()
- cam.rotation = player.rotation
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement