Godsim/scripts/God.gd

58 lines
1.8 KiB
GDScript3
Raw Normal View History

2024-05-30 02:14:08 +03:00
extends Node3D
const SENSETIVITY = 0.009;
var walk = 0.25
@onready var head = $"."
@onready var camera = $"./Camera"
@onready var ui = $"./UI"
@onready var velocity_label: Label = ui.find_child("velocity_label")
2024-05-30 06:55:13 +03:00
@onready var eye_raycast: RayCast3D = $"./Camera/eye"
@onready var earth = $"../Earth"
2024-05-30 02:14:08 +03:00
func _ready():
camera.make_current()
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
func _unhandled_input(event):
if Input.is_action_pressed("MWU"):
walk += walk / 5.
if Input.is_action_pressed("MWD"):
walk -= walk / 5.
walk = clamp(snapped(walk, 0.0005), 0.01, 15)
if event is InputEventMouseMotion:
head.rotate_y(-event.relative.x * SENSETIVITY)
camera.rotate_x(-event.relative.y * SENSETIVITY)
camera.rotation.x = clamp(camera.rotation.x, deg_to_rad(-90), deg_to_rad(90))
func _physics_process(delta):
velocity_label.text = "Velocity: " + str(walk)
var input_dir = Input.get_vector("left", "right", "forward", "backward")
#var direction = head.transform.rotation
var direction = (head.transform.basis * Vector3(input_dir.x, input_dir.x, input_dir.y)).normalized()
#var direction = (head.transform.basis * Vector2(input_dir.x, input_dir.y)).normalized()
var velocity = Vector3.ZERO
var speed
2024-05-30 06:55:13 +03:00
if Input.is_action_just_pressed("LMC") and eye_raycast.is_colliding():
var target = eye_raycast.get_collider()
if "TileType" in target and target.tile_type == 0:
target.tile_type = 2
target.update_tile()
earth.mark_free_tiles()
2024-05-30 02:14:08 +03:00
if Input.is_action_pressed("run"):
speed = walk * 2
else:
speed = walk
velocity.y = Input.get_vector("down", "up", "left", "right").x * speed
if direction:
velocity.x = direction.x * speed
velocity.z = direction.z * speed
else:
velocity.x = lerp(velocity.x, direction.x * speed, delta * 4)
velocity.z = lerp(velocity.z, direction.z * speed, delta * 4)
head.position += velocity