initial shit
This commit is contained in:
111
GameShit/PlayerController/ControllerSystem/Gerald.gd
Normal file
111
GameShit/PlayerController/ControllerSystem/Gerald.gd
Normal file
@@ -0,0 +1,111 @@
|
||||
extends CharacterBody3D
|
||||
|
||||
@export var isShiny : bool = false;
|
||||
@export var geraldColor : Color = Color(0.673, 0.03, 0.35, 1.0);
|
||||
@export var glowStrength : int = 2;
|
||||
|
||||
@export_group("Movement")
|
||||
@export var speed = 5.0
|
||||
@export var jump_velocity = 4.5
|
||||
@export var fly_speed = 8.0 # How fast you fly up/down/around
|
||||
@export var is_flying : bool = false # Toggle this in the inspector or via code
|
||||
|
||||
# Get the gravity from the project settings
|
||||
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
|
||||
|
||||
var PlayerMaterial : StandardMaterial3D = StandardMaterial3D.new();
|
||||
|
||||
func save():
|
||||
Save.saveGameData("test.tres")
|
||||
|
||||
func loadGame():
|
||||
Save.loadGameData("test.tres")
|
||||
|
||||
func fcm():
|
||||
$Camera3D/CanvasLayer/ChatBox.visible = not $Camera3D/CanvasLayer/ChatBox.visible
|
||||
if $Camera3D/CanvasLayer/ChatBox.visible:
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
|
||||
MainGame.isInputLocked = true
|
||||
else:
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||
MainGame.isInputLocked = false
|
||||
|
||||
func _ready() -> void:
|
||||
MainGame.hideChatbox.connect(fcm)
|
||||
$Camera3D/MeshInstance3D.material_override = PlayerMaterial
|
||||
if isShiny:
|
||||
PlayerMaterial.emission_enabled = true;
|
||||
PlayerMaterial.emission = geraldColor;
|
||||
PlayerMaterial.emission_energy_multiplier = glowStrength;
|
||||
PlayerMaterial.roughness = 0.05;
|
||||
PlayerMaterial.metallic = 1.0;
|
||||
PlayerMaterial.albedo_color = geraldColor;
|
||||
$Label3D.text=MainGame.username
|
||||
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if Input.is_action_just_pressed("fly"):
|
||||
is_flying = not is_flying
|
||||
if !MainGame.isInputLocked:
|
||||
if Input.is_action_just_pressed("save"):
|
||||
save()
|
||||
elif Input.is_action_just_pressed("load"):
|
||||
loadGame()
|
||||
if !$Camera3D/CanvasLayer/ChatBox/Panel/Panel2/Input.has_focus():
|
||||
if Input.is_action_just_pressed("chat"):
|
||||
$Camera3D/CanvasLayer/ChatBox.visible = not $Camera3D/CanvasLayer/ChatBox.visible
|
||||
if $Camera3D/CanvasLayer/ChatBox.visible:
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
|
||||
MainGame.isInputLocked = true
|
||||
else:
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||
MainGame.isInputLocked = false
|
||||
|
||||
func _physics_process(delta):
|
||||
|
||||
|
||||
if is_flying:
|
||||
handle_flight_movement(delta)
|
||||
else:
|
||||
if !MainGame.isInputLocked:
|
||||
handle_ground_movement(delta)
|
||||
move_and_slide()
|
||||
|
||||
func handle_ground_movement(delta):
|
||||
if not is_on_floor():
|
||||
velocity.y -= gravity * delta
|
||||
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
|
||||
velocity.y = jump_velocity
|
||||
var input_dir = Input.get_vector("move_left", "move_right", "move_forward", "move_backward")
|
||||
var cam_basis = $Camera3D.global_transform.basis
|
||||
var forward = Vector3(cam_basis.z.x, 0, cam_basis.z.z).normalized()
|
||||
var right = Vector3(cam_basis.x.x, 0, cam_basis.x.z).normalized()
|
||||
var direction = (forward * input_dir.y + right * input_dir.x).normalized()
|
||||
if direction != Vector3.ZERO:
|
||||
velocity.x = direction.x * speed
|
||||
velocity.z = direction.z * speed
|
||||
else:
|
||||
velocity.x = 0
|
||||
velocity.z = 0
|
||||
|
||||
func handle_flight_movement(delta):
|
||||
var input_dir = Input.get_vector("move_left", "move_right", "move_forward", "move_backward")
|
||||
var cam_basis = $Camera3D.global_transform.basis
|
||||
var forward = Vector3(cam_basis.z.x, 0, cam_basis.z.z).normalized()
|
||||
var right = Vector3(cam_basis.x.x, 0, cam_basis.x.z).normalized()
|
||||
var direction = (forward * input_dir.y + right * input_dir.x).normalized()
|
||||
if direction != Vector3.ZERO:
|
||||
velocity.x = direction.x * fly_speed
|
||||
velocity.z = direction.z * fly_speed
|
||||
else:
|
||||
velocity.x = 0
|
||||
velocity.z = 0
|
||||
var fly_up = Input.is_physical_key_pressed(KEY_SPACE)
|
||||
var fly_down = Input.is_physical_key_pressed(KEY_C)
|
||||
var fly_dir = 0
|
||||
if fly_up:
|
||||
fly_dir += 1
|
||||
if fly_down:
|
||||
fly_dir -= 1
|
||||
velocity.y = fly_dir * fly_speed
|
||||
Reference in New Issue
Block a user