playing around with gridmaps

This commit is contained in:
Clevertop 2024-08-10 16:00:46 +10:00
parent 7b32beeff6
commit b2cda89489
26 changed files with 650 additions and 20 deletions

View file

@ -1,5 +1,7 @@
extends CharacterBody3D
@export var camera : Camera3D
@export var mouse_sensitivity : float = 0.003 # TODO: this is sketchy check that its framerate independant pls
const SPEED = 5.0
const JUMP_VELOCITY = 4.5
@ -7,6 +9,8 @@ const JUMP_VELOCITY = 4.5
# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
func _ready():
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
func _physics_process(delta):
# Add the gravity.
@ -14,12 +18,19 @@ func _physics_process(delta):
velocity.y -= gravity * delta
# Handle jump.
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y = JUMP_VELOCITY
#free the mouse for debugging
if Input.is_action_just_pressed("esc"):
if (Input.mouse_mode == Input.MOUSE_MODE_CAPTURED):
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
else:
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var input_dir = Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
var input_dir = Input.get_vector("mov_left", "mov_right", "mov_up", "mov_down")
var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
if direction:
velocity.x = direction.x * SPEED
@ -29,3 +40,11 @@ func _physics_process(delta):
velocity.z = move_toward(velocity.z, 0, SPEED)
move_and_slide()
func _input(event):
# camera control
if event is InputEventMouseMotion and Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:
rotate_y(-event.relative.x * mouse_sensitivity)
camera.rotate_x(-event.relative.y * mouse_sensitivity)
camera.rotation.x = clampf(camera.rotation.x, -deg_to_rad(70), deg_to_rad(70))

View file

@ -1,12 +0,0 @@
extends Node3D
@export var camera : Camera3D
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass