forked from unfa/liblast
Added shooting
parent
7f1d6228a5
commit
2f344d1989
2
Game.gd
2
Game.gd
|
@ -69,8 +69,8 @@ sync func check_players(player_names):
|
|||
func add_player(id, check=true):
|
||||
var player = player_scene.instance()
|
||||
|
||||
$Players.add_child(player)
|
||||
player.name = str(id)
|
||||
$Players.add_child(player)
|
||||
player.set_network_master(id)
|
||||
player.translation += Vector3(0.0, 3.0, 0.0)
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
|
||||
[node name="Game" type="Spatial"]
|
||||
script = ExtResource( 2 )
|
||||
is_server = false
|
||||
SERVER_IP = "127.0.0.1"
|
||||
|
||||
[node name="Level" parent="." instance=ExtResource( 3 )]
|
||||
|
|
35
Player.gd
35
Player.gd
|
@ -11,9 +11,14 @@ const WALK_DECEL = 0.1
|
|||
|
||||
const MOUSE_SENSITIVITY = 1.0 / 300
|
||||
|
||||
export var max_health = 150
|
||||
onready var health = max_health
|
||||
|
||||
onready var camera = $Camera
|
||||
onready var debug = $Debug
|
||||
|
||||
onready var crosshair_pos = $CrosshairContainer.rect_size / 2
|
||||
|
||||
var velocity = Vector3.ZERO
|
||||
|
||||
var walkDirection = Vector2.ZERO
|
||||
|
@ -55,12 +60,12 @@ remote func walk(direction: Vector2):
|
|||
debug.text += "\ncurrentVelocity: " + String(currentVelocity)
|
||||
debug.text += "\nvelocity: " + String(velocity)
|
||||
debug.text += "\nis_on_floor(): " + String(is_on_floor())
|
||||
|
||||
debug.text += "\nhealth: " + String(health)
|
||||
|
||||
velocity.x = lerp(velocity.x, walkVelocity.rotated(- self.rotation.y).y, interpolation)
|
||||
velocity.z = lerp(velocity.z, - walkVelocity.rotated(- self.rotation.y).x, interpolation)
|
||||
|
||||
remote func jump():
|
||||
print("JUMP")
|
||||
if is_on_floor():
|
||||
velocity.y = JUMP_VELOCITY
|
||||
|
||||
|
@ -84,6 +89,25 @@ func _physics_process(delta):
|
|||
|
||||
rset("translation", translation)
|
||||
|
||||
master func on_hit():
|
||||
health -= 30
|
||||
print(health)
|
||||
|
||||
func shoot():
|
||||
var space_state = get_world().direct_space_state
|
||||
|
||||
var from = $Camera.project_ray_origin(crosshair_pos)
|
||||
var to = from + $Camera.project_ray_normal(crosshair_pos) * 1000
|
||||
|
||||
var result = space_state.intersect_ray(from, to)
|
||||
|
||||
if "collider" in result:
|
||||
var hit = result.collider
|
||||
print(hit)
|
||||
if hit.has_method("on_hit"):
|
||||
print("askdjhgfv")
|
||||
hit.rpc("on_hit")
|
||||
|
||||
func _input(event):
|
||||
if str(get_tree().get_network_unique_id()) != name:
|
||||
return
|
||||
|
@ -101,7 +125,6 @@ func _input(event):
|
|||
jump()
|
||||
|
||||
# Walk
|
||||
|
||||
if event.is_action_pressed("MoveForward"):
|
||||
walkDirection.x += 1
|
||||
if event.is_action_pressed("MoveBack"):
|
||||
|
@ -120,14 +143,18 @@ func _input(event):
|
|||
if event.is_action_released("MoveLeft"):
|
||||
walkDirection.y -= -1
|
||||
|
||||
if event.is_action_pressed("WeaponPrimary"):
|
||||
shoot()
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
rset_config("translation", MultiplayerAPI.RPC_MODE_SYNC)
|
||||
|
||||
# only show the debug label on local machine
|
||||
if name != String(get_tree().get_network_unique_id()):
|
||||
if name != "1": # String(get_tree().get_network_unique_id()):
|
||||
debug.hide()
|
||||
print(get_tree().get_network_unique_id())
|
||||
print(name)
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
#func _process(delta):
|
||||
|
|
17
Player.tscn
17
Player.tscn
|
@ -1,6 +1,7 @@
|
|||
[gd_scene load_steps=4 format=2]
|
||||
[gd_scene load_steps=5 format=2]
|
||||
|
||||
[ext_resource path="res://Player.gd" type="Script" id=1]
|
||||
[ext_resource path="res://icon.png" type="Texture" id=2]
|
||||
|
||||
[sub_resource type="CapsuleShape" id=1]
|
||||
|
||||
|
@ -30,3 +31,17 @@ text = "Debug"
|
|||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="CrosshairContainer" type="CenterContainer" parent="."]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="Crosshair" type="TextureRect" parent="CrosshairContainer"]
|
||||
margin_left = 480.0
|
||||
margin_top = 268.0
|
||||
margin_right = 544.0
|
||||
margin_bottom = 332.0
|
||||
texture = ExtResource( 2 )
|
||||
|
|
|
@ -46,6 +46,16 @@ MoveJump={
|
|||
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":32,"unicode":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
WeaponPrimary={
|
||||
"deadzone": 0.5,
|
||||
"events": [ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":1,"pressed":false,"doubleclick":false,"script":null)
|
||||
]
|
||||
}
|
||||
WeaponSecondary={
|
||||
"deadzone": 0.5,
|
||||
"events": [ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":2,"pressed":false,"doubleclick":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
[rendering]
|
||||
|
||||
|
|
Loading…
Reference in New Issue