initial shit
This commit is contained in:
42
GameShit/PlayerController/ControllerSystem/CameraDrag.gd
Normal file
42
GameShit/PlayerController/ControllerSystem/CameraDrag.gd
Normal file
@@ -0,0 +1,42 @@
|
||||
extends Camera3D
|
||||
|
||||
@export var sensitivity: float = 0.002
|
||||
@export var smooth_speed: float = 15.0
|
||||
|
||||
var target_yaw: float = 0.0
|
||||
var target_pitch: float = 0.0
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
target_yaw = rotation.y
|
||||
target_pitch = rotation.x
|
||||
# Capture the mouse immediately so you don't need to click to look around
|
||||
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
# Allows you to hit 'Escape' to free your mouse cursor if needed
|
||||
if event.is_action_pressed("ui_cancel"):
|
||||
if Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:
|
||||
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
|
||||
else:
|
||||
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
|
||||
|
||||
# Always looks around when the mouse moves (as long as it's captured)
|
||||
if event is InputEventMouseMotion and Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:
|
||||
target_yaw -= event.relative.x * sensitivity
|
||||
target_pitch -= event.relative.y * sensitivity
|
||||
target_pitch = clamp(target_pitch, deg_to_rad(-89), deg_to_rad(89))
|
||||
|
||||
# Zoom implementation (Clamped safely between 10 and 75 FOV)
|
||||
if event is InputEventMouseButton:
|
||||
if Input.is_key_pressed(KEY_ALT):
|
||||
if event.button_index == MOUSE_BUTTON_WHEEL_DOWN:
|
||||
fov = clamp(fov + 5, 10, 75)
|
||||
elif event.button_index == MOUSE_BUTTON_WHEEL_UP:
|
||||
fov = clamp(fov - 5, 10, 75)
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
|
||||
# Smooth Rotation
|
||||
rotation.y = lerp_angle(rotation.y, target_yaw, smooth_speed * delta)
|
||||
rotation.x = lerp(rotation.x, target_pitch, smooth_speed * delta)
|
||||
@@ -0,0 +1 @@
|
||||
uid://bcx7cyoq31cw6
|
||||
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
|
||||
1
GameShit/PlayerController/ControllerSystem/Gerald.gd.uid
Normal file
1
GameShit/PlayerController/ControllerSystem/Gerald.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://b7x6n68hgibrl
|
||||
84
GameShit/PlayerController/ControllerSystem/Interact.gd
Normal file
84
GameShit/PlayerController/ControllerSystem/Interact.gd
Normal file
@@ -0,0 +1,84 @@
|
||||
extends RayCast3D
|
||||
|
||||
var current_target: Node = null
|
||||
var curTarget: Node = null
|
||||
@export var mode = 0;
|
||||
var rot : int = 0
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if Input.is_key_pressed(KEY_E):
|
||||
rot += 2
|
||||
if Input.is_key_pressed(KEY_Q):
|
||||
rot -= 2
|
||||
|
||||
if Input.is_key_pressed(KEY_1):
|
||||
mode = 0
|
||||
elif Input.is_key_pressed(KEY_2):
|
||||
mode = 1
|
||||
elif Input.is_key_pressed(KEY_3):
|
||||
mode = 2
|
||||
|
||||
|
||||
func spawnObjectByID(ObjectID:String, position:Vector3, rotation:int):
|
||||
var segments = ObjectID.split(":")
|
||||
var objectScene = load("res://WorldObjects/{namespace}/{id}.tscn".format({"namespace": segments[0], "id": segments[1]}))
|
||||
|
||||
var object = objectScene.instantiate()
|
||||
object.global_position = position
|
||||
object.rotation_degrees = Vector3(0, rotation, 0)
|
||||
|
||||
get_tree().current_scene.get_node("objects").add_child(object)
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event is InputEventMouseButton:
|
||||
if not MainGame.canPlaceBlock:
|
||||
var is_left = event.button_index == MOUSE_BUTTON_LEFT
|
||||
var is_right = event.button_index == MOUSE_BUTTON_RIGHT
|
||||
|
||||
if is_left or is_right:
|
||||
if event.pressed:
|
||||
if is_colliding():
|
||||
var collider = get_collider()
|
||||
var target = _find_interactable_node(collider)
|
||||
if target:
|
||||
current_target = target
|
||||
if current_target.has_method("_interact_press"):
|
||||
# If it's a right click, pass true for the alt interaction
|
||||
current_target._interact_press(is_right)
|
||||
else:
|
||||
# Handle releasing the click
|
||||
if current_target and current_target.has_method("_interact_release"):
|
||||
current_target._interact_release()
|
||||
current_target = null
|
||||
elif MainGame.canPlaceBlock:
|
||||
var is_left = event.button_index == MOUSE_BUTTON_LEFT
|
||||
|
||||
if is_left:
|
||||
if event.pressed:
|
||||
spawnObjectByID(MainGame.selectedBlockID, get_collision_point(), rot)
|
||||
if MainGame.currentHeldItemID == "base:hammer":
|
||||
var is_left = event.button_index == MOUSE_BUTTON_LEFT
|
||||
if is_left:
|
||||
if event.pressed:
|
||||
var collider = get_collider()
|
||||
var target = _findBreakableNode(collider)
|
||||
if target:
|
||||
curTarget = target
|
||||
if curTarget.has_method("_destroy"):
|
||||
curTarget._destroy()
|
||||
|
||||
|
||||
func _find_interactable_node(node: Node) -> Node:
|
||||
while node != null:
|
||||
if node.has_method("_interact_press"):
|
||||
return node
|
||||
node = node.get_parent()
|
||||
return null
|
||||
|
||||
func _findBreakableNode(node: Node) -> Node:
|
||||
while node != null:
|
||||
if node.has_method("_destroy"):
|
||||
return node
|
||||
node = node.get_parent()
|
||||
return null
|
||||
@@ -0,0 +1 @@
|
||||
uid://d2r0ovdfa5y18
|
||||
104
GameShit/PlayerController/ControllerSystem/PlayerController.tscn
Normal file
104
GameShit/PlayerController/ControllerSystem/PlayerController.tscn
Normal file
@@ -0,0 +1,104 @@
|
||||
[gd_scene format=3 uid="uid://h6pvjvocpe1y"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://bcx7cyoq31cw6" path="res://GameShit/PlayerController/ControllerSystem/CameraDrag.gd" id="1_2be4l"]
|
||||
[ext_resource type="Script" uid="uid://b7x6n68hgibrl" path="res://GameShit/PlayerController/ControllerSystem/Gerald.gd" id="1_3mwrl"]
|
||||
[ext_resource type="Texture2D" uid="uid://djghgojdnndiq" path="res://GameShit/PlayerController/ControllerSystem/crosshair.png" id="3_1hgir"]
|
||||
[ext_resource type="Script" uid="uid://d2r0ovdfa5y18" path="res://GameShit/PlayerController/ControllerSystem/Interact.gd" id="3_y00gc"]
|
||||
[ext_resource type="Script" uid="uid://csqbc3n5gn47h" path="res://GameShit/PlayerController/Hotbar/HotBar.gd" id="6_y6phc"]
|
||||
[ext_resource type="PackedScene" uid="uid://cjdago36f5tk1" path="res://GameShit/PlayerController/Hotbar/HotbarSlot.tscn" id="7_eb4xd"]
|
||||
[ext_resource type="Resource" uid="uid://ng8hm4a1u2ya" path="res://GameShit/PlayerController/Hotbar/MainBar.res" id="8_jteqg"]
|
||||
[ext_resource type="PackedScene" uid="uid://bliihydr5ja7g" path="res://GameShit/PlayerController/ChatSystem/ChatBox.tscn" id="8_x05u2"]
|
||||
|
||||
[sub_resource type="SphereMesh" id="SphereMesh_3mwrl"]
|
||||
|
||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_3mwrl"]
|
||||
|
||||
[node name="PlayerController" type="CharacterBody3D" unique_id=1597560541 groups=["saveable"]]
|
||||
script = ExtResource("1_3mwrl")
|
||||
glowStrength = 140000
|
||||
|
||||
[node name="Camera3D" type="Camera3D" parent="." unique_id=866350707]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.496, 0)
|
||||
current = true
|
||||
script = ExtResource("1_2be4l")
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="Camera3D" unique_id=1586810034]
|
||||
mesh = SubResource("SphereMesh_3mwrl")
|
||||
|
||||
[node name="RayCast3D" type="RayCast3D" parent="Camera3D" unique_id=725234463]
|
||||
unique_name_in_owner = true
|
||||
transform = Transform3D(1, 0, 0, 0, -4.371139e-08, -1, 0, 1, -4.371139e-08, 0, 0, -0.51586515)
|
||||
target_position = Vector3(0, -4, 0)
|
||||
script = ExtResource("3_y00gc")
|
||||
|
||||
[node name="CanvasLayer" type="CanvasLayer" parent="Camera3D" unique_id=1005709652]
|
||||
|
||||
[node name="TextureRect" type="TextureRect" parent="Camera3D/CanvasLayer" unique_id=1252526888]
|
||||
anchors_preset = 8
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_left = -10.400024
|
||||
offset_top = -9.740021
|
||||
offset_right = 10.400024
|
||||
offset_bottom = 9.740021
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
scale = Vector2(0.5, 0.5)
|
||||
size_flags_horizontal = 4
|
||||
size_flags_vertical = 4
|
||||
texture = ExtResource("3_1hgir")
|
||||
metadata/_edit_use_anchors_ = true
|
||||
|
||||
[node name="HotBar" type="Control" parent="Camera3D/CanvasLayer" unique_id=1228004643 node_paths=PackedStringArray("HotbarContainer")]
|
||||
layout_mode = 3
|
||||
anchors_preset = 7
|
||||
anchor_left = 0.5
|
||||
anchor_top = 1.0
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 0
|
||||
size_flags_horizontal = 4
|
||||
size_flags_vertical = 8
|
||||
script = ExtResource("6_y6phc")
|
||||
slotScene = ExtResource("7_eb4xd")
|
||||
HotbarContainer = NodePath("HBoxContainer")
|
||||
hotbar = ExtResource("8_jteqg")
|
||||
metadata/_edit_use_anchors_ = true
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="Camera3D/CanvasLayer/HotBar" unique_id=569216010]
|
||||
custom_minimum_size = Vector2(40, 40)
|
||||
layout_mode = 1
|
||||
anchors_preset = 7
|
||||
anchor_left = 0.5
|
||||
anchor_top = 1.0
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 1.0
|
||||
offset_left = -196.0
|
||||
offset_top = -40.0
|
||||
offset_right = 196.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 0
|
||||
theme_override_constants/separation = 50
|
||||
alignment = 1
|
||||
metadata/_edit_use_anchors_ = true
|
||||
|
||||
[node name="ChatBox" parent="Camera3D/CanvasLayer" unique_id=756491211 instance=ExtResource("8_x05u2")]
|
||||
visible = false
|
||||
anchors_preset = 4
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.5
|
||||
grow_horizontal = 1
|
||||
pivot_offset = Vector2(0, 120)
|
||||
metadata/_edit_use_anchors_ = true
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="." unique_id=639269486]
|
||||
transform = Transform3D(0.5, 0, 0, 0, 1, 0, 0, 0, 0.5, 0, 0, 0)
|
||||
shape = SubResource("CapsuleShape3D_3mwrl")
|
||||
|
||||
[node name="Label3D" type="Label3D" parent="." unique_id=2066773761]
|
||||
transform = Transform3D(-0.9999846, 0, 0.0055676177, 0, 1, 0, -0.0055676177, 0, -0.9999846, 0, 1.6802876, 0)
|
||||
text = "USERNAME"
|
||||
BIN
GameShit/PlayerController/ControllerSystem/crosshair.png
Normal file
BIN
GameShit/PlayerController/ControllerSystem/crosshair.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 197 B |
@@ -0,0 +1,42 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://djghgojdnndiq"
|
||||
path.s3tc="res://.godot/imported/crosshair.png-6671a2781fe821ac2264c60589cc7d1e.s3tc.ctex"
|
||||
path.etc2="res://.godot/imported/crosshair.png-6671a2781fe821ac2264c60589cc7d1e.etc2.ctex"
|
||||
metadata={
|
||||
"imported_formats": ["s3tc_bptc", "etc2_astc"],
|
||||
"vram_texture": true
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://GameShit/PlayerController/ControllerSystem/crosshair.png"
|
||||
dest_files=["res://.godot/imported/crosshair.png-6671a2781fe821ac2264c60589cc7d1e.s3tc.ctex", "res://.godot/imported/crosshair.png-6671a2781fe821ac2264c60589cc7d1e.etc2.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=2
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/uastc_level=0
|
||||
compress/rdo_quality_loss=0.0
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=true
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/channel_remap/red=0
|
||||
process/channel_remap/green=1
|
||||
process/channel_remap/blue=2
|
||||
process/channel_remap/alpha=3
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=0
|
||||
Reference in New Issue
Block a user