on windows: try to shoot into camera look position

pull/28/head
DJh2o2 2025-07-21 11:59:16 +07:00
parent d0f45f3009
commit 181ee364a8
14 changed files with 227 additions and 19 deletions

@ -1,5 +1,5 @@
{
"godotTools.editorPath.godot4": "/home/sascha/Godot/Godot_v4.5-beta3_linux.x86_64",
"godotTools.editorPath.godot4": "c:\\Program Files\\Godot\\Godot_v4.5-beta3_win64.exe",
"git.alwaysShowStagedChangesResourceGroup": false,
"git.enableCommitSigning": true
}

@ -0,0 +1,41 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://b45epb0j7ul34"
path.s3tc="res://.godot/imported/dungeon_texture.png-481129781fe9a2b7c7250c2568305648.s3tc.ctex"
metadata={
"imported_formats": ["s3tc_bptc"],
"vram_texture": true
}
[deps]
source_file="res://resources/models/dungeon/textures/dungeon_texture.png"
dest_files=["res://.godot/imported/dungeon_texture.png-481129781fe9a2b7c7250c2568305648.s3tc.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

@ -3,7 +3,7 @@
importer="texture"
type="CompressedTexture2D"
uid="uid://ui267ctxnrgl"
path.s3tc="res://.godot/imported/texture.png-006df64ca70c5c353d5e022c852536d8.s3tc.ctex"
path.s3tc="res://.godot/imported/texture.png-5bb346f39e1c43017252a8b573e12dfc.s3tc.ctex"
metadata={
"imported_formats": ["s3tc_bptc"],
"vram_texture": true
@ -11,8 +11,8 @@ metadata={
[deps]
source_file="res://resources/models/dungeon/Textures/texture.png"
dest_files=["res://.godot/imported/texture.png-006df64ca70c5c353d5e022c852536d8.s3tc.ctex"]
source_file="res://resources/models/dungeon/textures/texture.png"
dest_files=["res://.godot/imported/texture.png-5bb346f39e1c43017252a8b573e12dfc.s3tc.ctex"]
[params]

@ -0,0 +1,12 @@
[gd_resource type="StandardMaterial3D" load_steps=2 format=3 uid="uid://b471l7axr3lfm"]
[ext_resource type="Texture2D" uid="uid://dvkrw7iq1wb3d" path="res://resources/models/dungeon/Textures/dungeon_texture.png" id="1_xkymj"]
[resource]
resource_name = "texture"
albedo_texture = ExtResource("1_xkymj")
metallic = 1.0
roughness = 0.45
emission_enabled = true
emission = Color(0.879605, 0.764761, 1.15514e-06, 1)
emission_energy_multiplier = 0.5

@ -0,0 +1,41 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://b45epb0j7ul34"
path.s3tc="res://.godot/imported/dungeon_texture.png-481129781fe9a2b7c7250c2568305648.s3tc.ctex"
metadata={
"imported_formats": ["s3tc_bptc"],
"vram_texture": true
}
[deps]
source_file="res://resources/models/dungeon/textures/dungeon_texture.png"
dest_files=["res://.godot/imported/dungeon_texture.png-481129781fe9a2b7c7250c2568305648.s3tc.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

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://dvkrw7iq1wb3d"
path.s3tc="res://.godot/imported/dungeon_texture.png-4348596a438780158879d29c23a36d28.s3tc.ctex"
metadata={
"imported_formats": ["s3tc_bptc"],
"vram_texture": true
}
[deps]
source_file="res://resources/models/dungeon/Textures/dungeon_texture.png"
dest_files=["res://.godot/imported/dungeon_texture.png-4348596a438780158879d29c23a36d28.s3tc.ctex"]
[params]
compress/mode=2
compress/high_quality=false
compress/lossy_quality=0.7
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/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

@ -0,0 +1,8 @@
[gd_resource type="StandardMaterial3D" load_steps=2 format=3 uid="uid://c28w5hk2x00s7"]
[ext_resource type="Texture2D" uid="uid://3i63817g50qe" path="res://resources/models/dungeon/Textures/dungeon_texture.png" id="1_hymfh"]
[resource]
resource_name = "texture"
albedo_texture = ExtResource("1_hymfh")
roughness = 0.45

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

@ -0,0 +1,41 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://ui267ctxnrgl"
path.s3tc="res://.godot/imported/texture.png-5bb346f39e1c43017252a8b573e12dfc.s3tc.ctex"
metadata={
"imported_formats": ["s3tc_bptc"],
"vram_texture": true
}
[deps]
source_file="res://resources/models/dungeon/textures/texture.png"
dest_files=["res://.godot/imported/texture.png-5bb346f39e1c43017252a8b573e12dfc.s3tc.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

@ -0,0 +1,8 @@
[gd_resource type="StandardMaterial3D" load_steps=2 format=3 uid="uid://fqum6ej0a88y"]
[ext_resource type="Texture2D" uid="uid://mmlj0yfrtogg" path="res://resources/models/dungeon/dungeon_texture.png" id="1_t704n"]
[resource]
resource_name = "texture"
albedo_texture = ExtResource("1_t704n")
roughness = 0.45

@ -2,7 +2,7 @@ class_name Player extends Unit
@export var mouse_sensitivity := 0.006
@export var rotation_speed := 24.0
@export var joypad_sensitivity := 2
@export var joypad_sensitivity := 2.0
@export var spring_arm: SpringArm3D
var gold := 0:
@ -29,14 +29,16 @@ func _physics_process(delta: float) -> void:
if velocity.length() > 1.0:
model.rotation.y = lerp_angle(model.rotation.y, spring_arm.rotation.y, rotation_speed * delta)
move_camera_joypad(delta)
func move_camera_joypad(delta: float) -> void:
var x_axis = Input.get_joy_axis(0, JOY_AXIS_RIGHT_X)
var y_axis = Input.get_joy_axis(0, JOY_AXIS_RIGHT_Y)
spring_arm.rotation.y -= x_axis * joypad_sensitivity * delta
spring_arm.rotation.x -= y_axis * joypad_sensitivity * delta
# Use joypad to move camera
if x_axis != 0.0 or y_axis != 0.0:
move_camera_joypad(x_axis, y_axis, delta)
func move_camera_joypad(x: float, y: float, delta: float) -> void:
spring_arm.rotation.x -= y * joypad_sensitivity * delta
spring_arm.rotation_degrees.x = clamp(spring_arm.rotation_degrees.x, -90.0, 30.0)
spring_arm.rotation.y -= x * joypad_sensitivity * delta
func player_game_over():
GameManager.game_over()

@ -1,12 +1,14 @@
class_name Projectile extends Node3D
var speed: float = 0.0
var direction: Vector3
var damage_amount: float = 3
@onready var ray_cast: RayCast3D = $RayCast3D
func _physics_process(delta):
if speed > 0.0:
translate(-transform.basis.x * speed * delta)
#translate(direction * speed * delta)
#translate(Vector3.FORWARD * speed * delta)
if ray_cast.is_colliding():
var collider = ray_cast.get_collider()
@ -24,7 +26,8 @@ func _physics_process(delta):
collider.call("take_damage", damage_amount)
func shoot() -> void:
print("Shooting arrow...")
func shoot(new_direction: Vector3) -> void:
direction = new_direction.normalized()
print("Shooting arrow towards ", direction)
speed = 20
ray_cast.enabled = true

@ -19,7 +19,6 @@ var current_arrow: Node3D
func _ready() -> void:
if loaded == true:
arrow_loaded()
print("Current arrow: " + str(current_arrow))
func _input(event: InputEvent) -> void:
# Shoot
@ -46,16 +45,25 @@ func _input(event: InputEvent) -> void:
anim_tree.set("parameters/conditions/aiming", state == States.aiming)
anim_tree.set("parameters/conditions/not_aiming", state != States.aiming)
#Camera
spring_arm.get_child(0).fov = 40 if state == States.aiming else 70
spring_arm.transform.origin.x = 0.5 # Shoulder offset
spring_arm.get_child(0).fov = 40 if state == States.aiming else 70
spring_arm.transform.origin.x = 0.5 # Shoulder offset
spring_arm.spring_length = 3.0
# Calls the _input() from player.gd
super._input(event)
super._input(event)
func shoot_arrow() -> void:
if current_arrow != null:
current_arrow.shoot()
var camera := get_viewport().get_camera_3d()
if camera:
# Zielpunkt im Raum berechnen (Ray vom Fadenkreuz)
var from = camera.project_ray_origin(get_viewport().get_visible_rect().size / 2)
var to = from + camera.project_ray_normal(get_viewport().get_visible_rect().size / 2) * 1000
var direction = (to - shoot_point.global_transform.origin).normalized()
current_arrow.shoot(direction)
else:
current_arrow.shoot() # Fallback
func arrow_loaded() -> void:
print("Arrow loaded...")

@ -6,30 +6,39 @@ extends Control
@onready var player: Player = get_tree().get_first_node_in_group("player")
@onready var cross_hair: BoxContainer = $CrossHair
var unit: Unit
func _ready() -> void:
# Connect signals from the player to update the UI elements
player.health_changed.connect(update_health_bar)
player.stamina_changed.connect(update_stamina_bar)
player.gold_changed.connect(update_gold_text)
player.player_loaded.connect(_on_player_loaded)
var unit = player as Unit
# Connect the state_changed signal to update the crosshair visibility
unit = player as Unit
unit.connect("state_changed", Callable(self, "_on_state_changed"))
func update_health_bar(current_health: int, maximum_health: int) -> void:
# Update the health bar with the current health
health_bar.value = (100.0 / maximum_health) * current_health
func update_stamina_bar(current_stamina: int, maximum_stamina: int) -> void:
# Update the stamina bar with the current stamina
stamina_bar.value = (100.0 / maximum_stamina) * current_stamina
func update_gold_text(gold: int) -> void:
# Update the gold label with the current gold amount
gold_label.text = "Gold: " + str(gold)
func _on_player_loaded() -> void:
# Initialize the health, stamina, and gold bars when the player is loaded
update_health_bar(player.health, player.maximum_health)
update_stamina_bar(player.stamina, player.maximum_stamina)
update_gold_text(player.gold)
func _on_state_changed(old_state: Unit.States, new_state: Unit.States):
if player.state == Unit.States.aiming:
# Update the crosshair visibility based on the new state
if new_state == Unit.States.aiming:
cross_hair.visible = true
else:
cross_hair.visible = false