Fix the aiming and bullet creation

This commit is contained in:
2025-02-01 18:03:00 +01:00
parent 33f1d57a50
commit bd91818682
19 changed files with 334 additions and 8089 deletions

View File

@ -7,6 +7,7 @@
extends CharacterBody3D
@export var jumping := false
var shooting := false
@export var input_direction := Vector2()
@onready var camera_mount = $CameraMount
@ -28,6 +29,7 @@ var current_weapon_damage: int
var current_weapon_bullet_speed: int
var current_weapon_cooldown_interwal: float
var look_dir: Vector2
var moving = false
func _ready() -> void:
global_position = $"..".initial_position
# -- TODO: It should not be hardcoded
@ -37,7 +39,7 @@ func _ready() -> void:
var scene: PackedScene = ResourceLoader.load(path)
var node: Node3D = scene.instantiate()
node.scale = Vector3(0.5,0.5,0.5)
node.position = Vector3(0.5, -0.5, -1.5)
node.position = Vector3(-0.3, -0.4, 0)
current_weapon_bullet_speed = node.bullet_speed
current_weapon_cooldown_interwal = node.cooldown
current_weapon_damage = node.damage
@ -47,14 +49,19 @@ func _ready() -> void:
func _input(event):
if multiplayer.get_unique_id() == get_multiplayer_authority():
if Input.is_action_just_pressed("jump"): jumping = true
if Input.is_action_pressed("shoot"): shooting = true
if Input.is_action_just_released("shoot"): shooting = false
if event is InputEventMouseMotion and Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:
look_dir = event.relative * 1
rotation.y -= look_dir.x * camera_sens * 1.0
camera_mount.rotation.x = clamp(camera_mount.rotation.x - look_dir.y * camera_sens * 1.0, -1.5, 1.5)
server_node.set_rotation_y.rpc_id(1, rotation.y)
server_node.set_rotation_x.rpc_id(1, rotation.x)
server_node.set_rotation_x.rpc_id(1, -camera_mount.rotation.x)
#server_node.set_input_direction.rpc_id(1, rotation.x, rotation.y)
if Input.is_action_pressed("move_left") or Input.is_action_pressed("move_right") or Input.is_action_pressed("move_forward") or Input.is_action_pressed("move_backwards"):
moving = true
else:
moving = false
@onready var server_node: PlayerServerNode = $"../ServerControlledNode"
# Called every frame. 'delta' is the elapsed time since the previous frame.
@ -64,27 +71,33 @@ func _physics_process(delta: float) -> void:
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
input_direction = Input.get_vector("move_left", "move_right", "move_forward", "move_backwards")
server_node.set_input_direction.rpc_id(1, input_direction)
if Input.is_action_just_pressed("jump"):
server_node.jump.rpc_id(1)
if Input.is_action_pressed("shot"): _shoot()
if multiplayer.get_unique_id() == get_multiplayer_authority():
if not is_on_floor():
velocity += get_gravity() * delta
if is_on_floor() && jumping:
server_node.jump.rpc_id(1)
velocity.y = JUMP_VELOCITY
if shooting:
server_node.shoot.rpc_id(1)
jumping = false
var direction := (transform.basis * Vector3(input_direction.x, 0, input_direction.y)).normalized()
if is_on_floor():
if direction:
#first_view_legs_anim.play("Run Forward")
gun_mount_anim.play("move")
velocity.x = direction.x * placeholder.character_speed
velocity.z = direction.z * placeholder.character_speed
else:
velocity.x = move_toward(velocity.x, 0, placeholder.character_speed)
velocity.z = move_toward(velocity.z, 0, placeholder.character_speed)
func _process(delta: float) -> void:
move_and_slide()
if moving:
gun_mount_anim.play("move")
else:
gun_mount_anim.stop()
move_and_slide()
var cant_shoot: bool = false