Added Player-Weapon trigger API

pull/50/head
unfa 2021-06-18 01:43:10 +02:00
parent cfaa3e2ba1
commit df17620149
2 changed files with 33 additions and 0 deletions

View File

@ -16,6 +16,8 @@ extends CharacterBody3D
@onready var body = $Body
@onready var mesh = $Mesh
@onready var weapon = $Head/Camera/Hand/Weapon
@onready var body_height = body.shape.height
@onready var body_y = body.position.y
@onready var mesh_height = mesh.mesh.mid_height
@ -115,6 +117,15 @@ func _input(event) -> void:
rpc_unreliable(&'aim', event)
if Input.is_action_just_pressed("trigger_primary"):
weapon.trigger(0, true)
elif Input.is_action_just_released("trigger_primary"):
weapon.trigger(0, false)
if Input.is_action_just_pressed("trigger_secondary"):
weapon.trigger(1, true)
elif Input.is_action_just_released("trigger_secondary"):
weapon.trigger(1, false)
func _physics_process(delta):
rpc_unreliable(&'set_global_transform', global_transform)
head.rpc_unreliable(&'set_rotation', head.get_rotation())

View File

@ -0,0 +1,22 @@
extends Node3D
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
#enum Trigger {TRIGGER_PRIMARY, TRIGGER_SECONDARY}
func trigger(index: int, active: bool) -> void:
print("Weapon " + str(name) + ", Trigger " + str(index) + ", active: " + str(active))
if index == 0 and active:
$Flash/FlashParticles.emmiting = true
# 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