You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
Gridmap/scripts/Camera3D.gd

45 lines
1.3 KiB

extends Camera3D
const MOVE_MARGIN = 20
const MOVE_SPEED = 30
const HEIGHT_OFFSET = 10
@export var min_zoom: float = 10
@export var max_zoom: float = 100
@export var zoom_sensibility: float = 1.4
@onready var ray = $RayCast3D
func _process(delta):
var m_pos = get_viewport().get_mouse_position()
calc_move(m_pos, delta)
if Input.is_action_just_released("zoom_in"):
zoom(-1000)
if Input.is_action_just_released("zoom_out"):
zoom(1000)
var height = ray.get_collision_point().y + HEIGHT_OFFSET
if position.y != height:
var tween = get_tree().create_tween()
tween.tween_property(self, "position:y", height, 0.1)
Global.world.player_position = Global.world.get_real_coordinates(Vector2i(position.x, position.z))
func calc_move(m_pos, delta):
var v_size = Vector2(1152, 648)
var move_vec = Vector3()
if m_pos.x < MOVE_MARGIN:
move_vec.x -= 1
if m_pos.y < MOVE_MARGIN:
move_vec.z -= 1
if m_pos.x > v_size.x - MOVE_MARGIN:
move_vec.x += 1
if m_pos.y > v_size.y - MOVE_MARGIN:
move_vec.z += 1
move_vec = move_vec.rotated(Vector3(0, 1, 0), rotation_degrees.y)
global_translate(move_vec * delta * MOVE_SPEED)
func zoom(direction : float):
#Zooming using fov
var new_fov = fov + (sign(direction) * pow(abs(direction),zoom_sensibility)/100 * get_process_delta_time())
fov = clamp(new_fov,min_zoom,max_zoom)