From c25901f552013905d08827f2ff004244a57f8d4f Mon Sep 17 00:00:00 2001 From: Clifton Palmer Date: Sun, 14 Nov 2021 18:32:36 -0600 Subject: [PATCH] Added stupid bullets --- player/bullet.gd | 17 +++++++++++++ player/bullet.tscn | 59 ++++++++++++++++++++++++++++++++++++++++++++++ player/player.gd | 12 ++++++++++ player/player.tscn | 9 ++++++- 4 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 player/bullet.gd create mode 100644 player/bullet.tscn diff --git a/player/bullet.gd b/player/bullet.gd new file mode 100644 index 0000000..0509ae2 --- /dev/null +++ b/player/bullet.gd @@ -0,0 +1,17 @@ +extends KinematicBody + + +# Declare member variables here. Examples: +# var a = 2 +# var b = "text" +var SPEED = 200 +var direction = Vector3.ZERO + +# 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): + translation += SPEED * direction * delta diff --git a/player/bullet.tscn b/player/bullet.tscn new file mode 100644 index 0000000..2a8ef2f --- /dev/null +++ b/player/bullet.tscn @@ -0,0 +1,59 @@ +[gd_scene load_steps=6 format=2] + +[ext_resource path="res://player/bullet.gd" type="Script" id=1] + +[sub_resource type="BoxShape" id=1] +extents = Vector3( 0.200265, 0.163217, 1.15937 ) + +[sub_resource type="VisualShaderNodeColorConstant" id=2] +constant = Color( 0.934058, 0.128752, 0, 1 ) + +[sub_resource type="VisualShader" id=3] +code = "shader_type spatial; +render_mode specular_schlick_ggx, unshaded; + + + + +void vertex() { +// Output:0 + +} + +void fragment() { +// Color:2 + vec3 n_out2p0 = vec3(0.934058, 0.128752, 0.000000); + float n_out2p1 = 1.000000; + +// Output:0 + ALBEDO = n_out2p0; + +} + +void light() { +// Output:0 + +} +" +graph_offset = Vector2( 0, 20.4406 ) +flags/unshaded = true +nodes/fragment/0/position = Vector2( 1560, 60 ) +nodes/fragment/2/node = SubResource( 2 ) +nodes/fragment/2/position = Vector2( 1040, 100 ) +nodes/fragment/connections = PoolIntArray( 2, 0, 0, 0 ) + +[sub_resource type="ShaderMaterial" id=4] +shader = SubResource( 3 ) + +[node name="bullet" type="KinematicBody"] +collision_layer = 2 +collision_mask = 0 +script = ExtResource( 1 ) + +[node name="CollisionShape" type="CollisionShape" parent="."] +shape = SubResource( 1 ) + +[node name="CSGSphere" type="CSGSphere" parent="."] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 11, 0, 0, 0 ) +material_override = SubResource( 4 ) +radius = 0.1 diff --git a/player/player.gd b/player/player.gd index fa2445f..2b608dc 100644 --- a/player/player.gd +++ b/player/player.gd @@ -6,6 +6,7 @@ const SPEED_TURN = 120 const SPEED_AIM = PI / 2 var velocity = Vector3() +var scene_bullet = preload("res://player/bullet.tscn") # Called when the node enters the scene tree for the first time. func _ready(): @@ -36,6 +37,17 @@ func get_player_input(delta): elif Input.is_action_pressed("player_aim_right"): rotate(Vector3.UP, -SPEED_AIM * delta) + # offense + if Input.is_action_pressed("player_fire"): + print("firing!") + fire_bullet() + +func fire_bullet(): + var bullet = scene_bullet.instance() + $"..".add_child(bullet) + bullet.translation = translation - transform.basis.x * 2 + bullet.rotation = rotation + bullet.direction = -transform.basis.z func _process(delta): # get velocity changes player asks for diff --git a/player/player.tscn b/player/player.tscn index 7dc0f4c..c96080c 100644 --- a/player/player.tscn +++ b/player/player.tscn @@ -56,6 +56,7 @@ surfaces/0 = { extents = Vector3( 3.72203, 0.878147, 3.13957 ) [node name="arwing" type="KinematicBody"] +collision_mask = 0 script = ExtResource( 3 ) [node name="mesh" type="Spatial" parent="."] @@ -80,4 +81,10 @@ shape = SubResource( 5 ) [node name="camera_pivot" type="Spatial" parent="."] [node name="Camera" type="Camera" parent="camera_pivot"] -transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 13.3084 ) +transform = Transform( 1, 0, 0, 0, 0.959634, 0.281253, 0, -0.281253, 0.959634, 0, 9.44245, 11.0721 ) + +[node name="bullet_origin_r" type="Spatial" parent="."] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, -2 ) + +[node name="bullet_origin_l" type="Spatial" parent="."] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -1, 0, -2 ) -- 2.47.2