Added bullets
This commit is contained in:
parent
7b382dcbe1
commit
8c1583c928
10 changed files with 246 additions and 1 deletions
BIN
.DS_Store
vendored
Normal file
BIN
.DS_Store
vendored
Normal file
Binary file not shown.
|
@ -7,6 +7,7 @@ const JUMP_VELOCITY = 4.5
|
|||
# Get the gravity from the project settings to be synced with RigidBody nodes.
|
||||
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
|
||||
|
||||
@export var Bullet = preload("res://objects/Bullet/Bullet.tscn")
|
||||
@onready var neck := $Neck
|
||||
@onready var camera := $Neck/Camera3D
|
||||
|
||||
|
@ -25,7 +26,7 @@ func _unhandled_input(event):
|
|||
var mousesense = Global.mouseSensitivity
|
||||
neck.rotate_y(-event.relative.x * mousesense)
|
||||
camera.rotate_x(-event.relative.y * mousesense)
|
||||
camera.rotation.x = clamp(camera.rotation.x, deg_to_rad(-35), deg_to_rad(60))
|
||||
camera.rotation.x = clamp(camera.rotation.x, deg_to_rad(-50), deg_to_rad(60))
|
||||
if Global.menuOpen == false:
|
||||
if Input.is_action_just_pressed("menu"):
|
||||
Global.menuOpen = true
|
||||
|
@ -63,4 +64,11 @@ func _physics_process(delta):
|
|||
else:
|
||||
velocity.x = move_toward(velocity.x, 0, SPEED)
|
||||
velocity.z = move_toward(velocity.z, 0, SPEED)
|
||||
if Input.is_action_just_pressed("shoot"):
|
||||
if Global.menuOpen == false:
|
||||
print("shoot")
|
||||
var b = Bullet.instantiate()
|
||||
owner.add_child(b)
|
||||
b.transform = $Neck/BulletGenerator.global_transform
|
||||
b.velocity = -b.global_transform.basis.z * b.muzzle_velocity
|
||||
move_and_slide()
|
||||
|
|
51
objects/Bullet/Bullet.gd
Normal file
51
objects/Bullet/Bullet.gd
Normal file
|
@ -0,0 +1,51 @@
|
|||
extends Area3D
|
||||
|
||||
signal exploded
|
||||
|
||||
@export var muzzle_velocity = 100 # How fast the bullets are
|
||||
@export var g = Vector3.DOWN * 20
|
||||
|
||||
var velocity = Vector3.ZERO
|
||||
|
||||
###### CHEATS
|
||||
var godmode = 0
|
||||
|
||||
|
||||
func _physics_process(delta):
|
||||
# velocity += g * delta # Uncomment this for bullet gravity
|
||||
look_at(transform.origin + velocity.normalized(), Vector3.UP)
|
||||
transform.origin += velocity * delta
|
||||
|
||||
for body in get_overlapping_bodies(): ### THIS IS OLD LOGIC, REPLACE. I'D RECOMMEND TO CHECK BY GROUP AND NOT BY NODE
|
||||
if get_overlapping_bodies().has(get_parent().get_node(^"PlayerTank")):
|
||||
print ("Found Player Tank")
|
||||
self.queue_free()
|
||||
if (godmode == 0):
|
||||
body.queue_free()
|
||||
Global.playerdead = 1
|
||||
Global.tankskilled = 0
|
||||
Global.beforedeathscene = get_tree().current_scene.filename
|
||||
get_tree().change_scene("res://Levels/Dead.tscn")
|
||||
else:
|
||||
if get_overlapping_bodies():
|
||||
if body.has_node("TankAI"):
|
||||
print ("Found AI Tank")
|
||||
Global.tankskilled = Global.tankskilled + 1
|
||||
if (Global.tankskilled == 10):
|
||||
if (Global.firstlevelcompleted == 0):
|
||||
Global.firstlevelcompleted = 1
|
||||
get_tree().change_scene("res://Levels/win-01.tscn")
|
||||
else:
|
||||
if (Global.firstlevelcompleted == 1):
|
||||
get_tree().change_scene("res://Levels/Win-02.tscn")
|
||||
Global.tankskilled = 0
|
||||
self.queue_free()
|
||||
body.queue_free()
|
||||
else:
|
||||
print ("Bullet Collided with something else")
|
||||
self.queue_free()
|
||||
|
||||
|
||||
func _on_Shell_body_entered(body):
|
||||
emit_signal("exploded", transform.origin)
|
||||
queue_free()
|
18
objects/Bullet/Bullet.tscn
Normal file
18
objects/Bullet/Bullet.tscn
Normal file
|
@ -0,0 +1,18 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://bklrmcxas4g5f"]
|
||||
|
||||
[ext_resource type="Script" path="res://Objects/Bullet/Bullet.gd" id="1"]
|
||||
[ext_resource type="PackedScene" uid="uid://pni78bumc5f5" path="res://objects/Bullet/model/Bullet.dae" id="2"]
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_chxfq"]
|
||||
size = Vector3(0.40456, 0.406836, 0.393048)
|
||||
|
||||
[node name="Bullet" type="Area3D" groups=["bullet"]]
|
||||
transform = Transform3D(0.979715, 0, 0, 0, 0.979715, 0, 0, 0, 0.979715, 0, 0, 0)
|
||||
script = ExtResource("1")
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="." groups=["bullet"]]
|
||||
transform = Transform3D(0.957696, 0, 0, 0, 1, 0, 0, 0, 1.66763, 0, 0, -0.295843)
|
||||
shape = SubResource("BoxShape3D_chxfq")
|
||||
|
||||
[node name="Bullet" parent="." instance=ExtResource("2")]
|
||||
transform = Transform3D(0.200224, 0, 0, 0, -8.75207e-09, 0.200224, 0, -0.200224, -8.75207e-09, 0, 0, 0)
|
130
objects/Bullet/model/Bullet.dae
Normal file
130
objects/Bullet/model/Bullet.dae
Normal file
File diff suppressed because one or more lines are too long
30
objects/Bullet/model/Bullet.dae.import
Normal file
30
objects/Bullet/model/Bullet.dae.import
Normal file
|
@ -0,0 +1,30 @@
|
|||
[remap]
|
||||
|
||||
importer="scene"
|
||||
importer_version=1
|
||||
type="PackedScene"
|
||||
uid="uid://pni78bumc5f5"
|
||||
path="res://.godot/imported/Bullet.dae-5bbc570d18bdc3c3b39c8ef588b2ee68.scn"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://objects/Bullet/model/Bullet.dae"
|
||||
dest_files=["res://.godot/imported/Bullet.dae-5bbc570d18bdc3c3b39c8ef588b2ee68.scn"]
|
||||
|
||||
[params]
|
||||
|
||||
nodes/root_type="Node3D"
|
||||
nodes/root_name="Scene Root"
|
||||
nodes/apply_root_scale=true
|
||||
nodes/root_scale=1.0
|
||||
meshes/ensure_tangents=true
|
||||
meshes/generate_lods=true
|
||||
meshes/create_shadow_meshes=true
|
||||
meshes/light_baking=0
|
||||
meshes/lightmap_texel_size=0.1
|
||||
skins/use_named_skins=true
|
||||
animation/import=true
|
||||
animation/fps=15
|
||||
animation/trimming=false
|
||||
import_script/path=""
|
||||
_subresources={}
|
BIN
objects/Bullet/model/Material_001.material
Normal file
BIN
objects/Bullet/model/Material_001.material
Normal file
Binary file not shown.
BIN
objects/Bullet/model/Material_002.material
Normal file
BIN
objects/Bullet/model/Material_002.material
Normal file
Binary file not shown.
|
@ -61,3 +61,8 @@ menu={
|
|||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194305,"unicode":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
shoot={
|
||||
"deadzone": 0.5,
|
||||
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":1,"pressed":false,"double_click":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
|
|
@ -20,3 +20,6 @@ shape = SubResource("BoxShape3D_rpt2n")
|
|||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.859224, 0)
|
||||
|
||||
[node name="Camera3D" type="Camera3D" parent="Neck"]
|
||||
|
||||
[node name="BulletGenerator" type="Marker3D" parent="Neck"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.104801, -0.858231)
|
||||
|
|
Loading…
Reference in a new issue