added autocannon ammo & firing

This commit is contained in:
Otto Naderer 2024-08-03 18:33:20 +03:00
parent 151172ec2a
commit 66ceb38f6f
9 changed files with 98 additions and 41 deletions

View File

@ -0,0 +1,22 @@
[remap]
importer="wavefront_obj"
importer_version=1
type="Mesh"
uid="uid://jwocs7p3hvvx"
path="res://.godot/imported/tround.obj-c32c36ce64cfbdf1c8c85ac70173987d.mesh"
[deps]
files=["res://.godot/imported/tround.obj-c32c36ce64cfbdf1c8c85ac70173987d.mesh"]
source_file="res://assets/meshes/ammo/tround.obj"
dest_files=["res://.godot/imported/tround.obj-c32c36ce64cfbdf1c8c85ac70173987d.mesh", "res://.godot/imported/tround.obj-c32c36ce64cfbdf1c8c85ac70173987d.mesh"]
[params]
generate_tangents=true
scale_mesh=Vector3(1, 1, 1)
offset_mesh=Vector3(0, 0, 0)
optimize_mesh=true
force_disable_mesh_compression=false

View File

@ -0,0 +1,24 @@
[gd_scene load_steps=5 format=3 uid="uid://2vxx8t3t4syf"]
[ext_resource type="Script" path="res://assets/scripts/ammo/round_autocannon.gd" id="1_tep0f"]
[ext_resource type="ArrayMesh" uid="uid://jwocs7p3hvvx" path="res://assets/meshes/ammo/tround.obj" id="2_mb2ep"]
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_8r3eg"]
albedo_color = Color(0.519414, 0, 0.0307446, 1)
emission_enabled = true
emission = Color(1, 1, 1, 1)
emission_energy_multiplier = 18.85
[sub_resource type="ConvexPolygonShape3D" id="ConvexPolygonShape3D_cvk15"]
points = PackedVector3Array(-6.14673e-07, -0.0525, -0.075, -0.0102477, -0.0514928, -0.075, 0.0102361, -0.0514928, -0.075, -6.14673e-07, -0.0525, 0.0749796, -0.0102477, -0.0514928, 0.0749796, -0.0200939, -0.0485121, -0.075, 0.0200824, -0.0485121, -0.075, 0.0102361, -0.0514928, 0.0749796, 0.00214746, -0.010833, 0.142579, -6.14673e-07, -0.0110386, 0.142579, -0.00215897, -0.010833, 0.142579, -0.0200939, -0.0485121, 0.0749796, -0.0291692, -0.0436609, -0.075, 0.0291577, -0.0436609, -0.075, 0.0200824, -0.0485121, 0.0749796, 0.00421331, -0.0101958, 0.142579, -0.00422482, -0.0101958, 0.142579, -0.0061365, -0.00917825, 0.142579, -0.0291692, -0.0436609, 0.0749796, -0.0371243, -0.0371241, -0.075, 0.0371128, -0.0371241, -0.075, 0.0291577, -0.0436609, 0.0749796, 0.006125, -0.00917825, 0.142579, -0.0078118, -0.00781127, 0.142579, -0.0371243, -0.0371241, 0.0749796, -0.043661, -0.029169, -0.075, 0.0436495, -0.029169, -0.075, 0.0371128, -0.0371241, 0.0749796, 0.00780029, -0.00781127, 0.142579, -0.00917875, -0.00613596, 0.142579, -0.043661, -0.029169, 0.0749796, -0.0485122, -0.0200935, -0.075, 0.0485007, -0.0200935, -0.075, 0.0436495, -0.029169, 0.0749796, 0.00916725, -0.00613596, 0.142579, -0.0102065, -0.00422426, 0.142579, -0.0485122, -0.0200935, 0.0749796, -0.0514928, -0.0102472, -0.075, 0.0514813, -0.0102472, -0.075, 0.0485007, -0.0200935, 0.0749796, 0.0101848, -0.00422426, 0.142579, -0.0108335, -0.00215838, 0.142579, -0.0514928, -0.0102472, 0.0749796, -0.0525, -1.02781e-05, -0.075, 0.0524988, -1.02781e-05, -0.075, 0.0514813, -0.0102472, 0.0749796, 0.0108117, -0.00215838, 0.142579, -0.0110391, -1.02781e-05, 0.142579, -0.0525, -1.02781e-05, 0.0749796, -0.0514928, 0.0102369, -0.075, 0.0514813, 0.0102369, -0.075, 0.0524988, -1.02781e-05, 0.0749796, 0.0110275, -1.02781e-05, 0.142579, -0.0108335, 0.0021481, 0.142579, -0.0514928, 0.0102369, 0.0749796, -0.0485122, 0.0200832, -0.075, 0.0485007, 0.0200832, -0.075, 0.0514813, 0.0102369, 0.0749796, 0.0108117, 0.0021481, 0.142579, -0.0102065, 0.00421398, 0.142579, -0.0485122, 0.0200832, 0.0749796, -0.043661, 0.0291587, -0.075, 0.0436495, 0.0291587, -0.075, 0.0485007, 0.0200832, 0.0749796, 0.0101848, 0.00421398, 0.142579, -0.00917875, 0.00612568, 0.142579, -0.043661, 0.0291587, 0.0749796, -0.0371243, 0.0371138, -0.075, 0.0371128, 0.0371138, -0.075, 0.0436495, 0.0291587, 0.0749796, 0.00916725, 0.00612568, 0.142579, -0.0078118, 0.007801, 0.142579, -0.0371243, 0.0371138, 0.0749796, -0.0291692, 0.0436506, -0.075, 0.0291577, 0.0436506, -0.075, 0.0371128, 0.0371138, 0.0749796, 0.00780029, 0.007801, 0.142579, -0.0061365, 0.00916797, 0.142579, -0.0291692, 0.0436506, 0.0749796, -0.0200939, 0.0485019, -0.075, 0.0200824, 0.0485019, -0.075, 0.0291577, 0.0436506, 0.0749796, 0.006125, 0.00916797, 0.142579, -0.00422482, 0.0101855, 0.142579, -0.0200939, 0.0485019, 0.0749796, -0.0102477, 0.0514825, -0.075, 0.0102361, 0.0514825, -0.075, 0.0200824, 0.0485019, 0.0749796, 0.00421331, 0.0101855, 0.142579, -0.00215897, 0.0108125, 0.142579, -0.0102477, 0.0514825, 0.0749796, -6.14673e-07, 0.0525, -0.075, 0.0102361, 0.0514825, 0.0749796, 0.00214746, 0.0108125, 0.142579, -6.14673e-07, 0.0110283, 0.142579, -6.14673e-07, 0.0525, 0.0749796)
[node name="RoundAutocannon" type="RigidBody3D"]
script = ExtResource("1_tep0f")
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1.36723, 0, 0, 0)
mesh = ExtResource("2_mb2ep")
surface_material_override/0 = SubResource("StandardMaterial3D_8r3eg")
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
shape = SubResource("ConvexPolygonShape3D_cvk15")

View File

@ -31,6 +31,7 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1, -0.934518, 1.28716)
use_as_traction = true
use_as_steering = true
wheel_rest_length = 0.3
wheel_friction_slip = 1.0
suspension_travel = 0.3
suspension_stiffness = 15.0
suspension_max_force = 25000.0
@ -42,6 +43,7 @@ mesh = ExtResource("2_4yh6h")
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1, -0.934518, -1.4)
use_as_traction = true
wheel_rest_length = 0.3
wheel_friction_slip = 5.0
suspension_travel = 0.3
suspension_stiffness = 15.0
suspension_max_force = 20000.0
@ -53,6 +55,7 @@ mesh = ExtResource("2_4yh6h")
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1, -0.934518, -1.4)
use_as_traction = true
wheel_rest_length = 0.3
wheel_friction_slip = 5.0
suspension_travel = 0.3
suspension_stiffness = 15.0
suspension_max_force = 20000.0
@ -66,6 +69,7 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1, -0.934518, 1.28716)
use_as_traction = true
use_as_steering = true
wheel_rest_length = 0.3
wheel_friction_slip = 1.0
suspension_travel = 0.3
suspension_stiffness = 15.0
suspension_max_force = 25000.0
@ -85,6 +89,12 @@ mesh = ExtResource("5_ymni4")
[node name="Camera3D" type="Camera3D" parent="turret/cannon"]
transform = Transform3D(-1, -4.76139e-08, 7.33189e-08, 0, 0.838671, 0.544639, -8.74228e-08, 0.544639, -0.838671, 0, 1.421, -3.761)
[node name="muzzle" type="Node3D" parent="turret/cannon"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 2.59087)
[node name="aimpoint" type="Node3D" parent="turret/cannon"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 10)
[node name="turret_collmesh" type="CollisionShape3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.520482, 0)
shape = SubResource("ConvexPolygonShape3D_pmy52")

View File

@ -0,0 +1,22 @@
extends RigidBody3D
var life_span = 0
# Called when the node enters the scene tree for the first time.
func _ready():
set_contact_monitor(true)
set_max_contacts_reported(5)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
life_span += delta
if life_span > 5:
print("removed shot")
queue_free()
func init_round(start:Node3D, aim_vec:Vector3):
position = start.global_position
transform.basis = start.global_transform.basis
#print(start.target_position)
set_linear_velocity(aim_vec.normalized() * 200.0)

View File

@ -2,7 +2,7 @@
extends VehicleBody3D
# Member variables
var s#hotscene = preload("res://tank-round.tscn")
var shotscene = preload("res://assets/scenes/round_autocannon.tscn")
@export var _steer_speed = 2.5
@export var _steer_limit = .8
@export var _engine_force = 1000.0
@ -25,23 +25,25 @@ func _input(ie):
var plus_pitch = view_sensitivity * -ie.relative.y
var plus_yaw = fmod(view_sensitivity * -ie.relative.x,360)
var can_rot = $turret/cannon.get_rotation()
print(plus_pitch)
#print(plus_pitch)
can_rot.x -= deg_to_rad(plus_pitch)
var can_elev = rad_to_deg(can_rot.x)
print(can_elev)
#if can_elev < 7 and can_elev > -30:
$turret/cannon.set_rotation(can_rot)
#print(can_elev)
if can_elev < 7 and can_elev > -30:
$turret/cannon.set_rotation(can_rot)
#print(cannon.get_global_transform().get_rotation())
$turret.rotate(Vector3(0,1,0), deg_to_rad(plus_yaw))
#elif ie is InputEventMouseButton:
# if ie.button_index == MOUSE_BUTTON_LEFT and ie.is_pressed():
# var shot = shotscene.instantiate()
# get_parent().add_child(shot)
# $turret_cshape/cannon_mesh/RayCast3D.
# var shot_dir = $turret_cshape/cannon_mesh/Aimpoint.get_global_transform().origin - $turret_cshape/cannon_mesh.get_global_transform().origin
# shot.set_transform($turret_cshape/cannon_mesh/Aimpoint.get_global_transform())
# shot.set_linear_velocity(shot_dir.normalized() * 100.0)
elif ie is InputEventMouseButton:
if ie.button_index == MOUSE_BUTTON_LEFT and ie.is_pressed():
var shot = shotscene.instantiate()
shot.init_round($turret/cannon/muzzle, $turret/cannon/aimpoint.global_position - $turret/cannon/muzzle.global_position)
get_tree().root.add_child(shot)
#
#shot.position = $turret/cannon/RayCast3D.global_position
#shot.transform.basis = $turret/cannon/RayCast3D.global_transform.basis
#print($turret/cannon/RayCast3D.target_position)
#shot.set_linear_velocity($turret/cannon/RayCast3D.position.normalized() * 100.0)
#shot.set_linear_velocity(shot.get_rotation().normalized() * 10)
#shot.connect("body_enter", self, "shot_hit")

View File

@ -1,22 +0,0 @@
[remap]
importer="wavefront_obj"
importer_version=1
type="Mesh"
uid="uid://jwocs7p3hvvx"
path="res://.godot/imported/tround.obj-7ba03cb9585ba0bfd65dc95a8649eed4.mesh"
[deps]
files=["res://.godot/imported/tround.obj-7ba03cb9585ba0bfd65dc95a8649eed4.mesh"]
source_file="res://models/tround.obj"
dest_files=["res://.godot/imported/tround.obj-7ba03cb9585ba0bfd65dc95a8649eed4.mesh", "res://.godot/imported/tround.obj-7ba03cb9585ba0bfd65dc95a8649eed4.mesh"]
[params]
generate_tangents=true
scale_mesh=Vector3(1, 1, 1)
offset_mesh=Vector3(0, 0, 0)
optimize_mesh=true
force_disable_mesh_compression=false

View File

@ -1,16 +1,15 @@
[gd_scene load_steps=3 format=2]
[gd_scene load_steps=3 format=3 uid="uid://lvsi1b47ypg0"]
[ext_resource path="res://models/tround.obj" type="ArrayMesh" id=1]
[ext_resource type="ArrayMesh" uid="uid://jwocs7p3hvvx" path="res://assets/meshes/ammo/tround.obj" id="1_ulxtk"]
[sub_resource type="CapsuleShape3D" id=1]
[sub_resource type="CapsuleShape3D" id="1"]
radius = 0.0575807
height = 0.184025
[node name="RigidBody3D" type="RigidBody3D"]
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
mesh = ExtResource( 1 )
material/0 = null
mesh = ExtResource("1_ulxtk")
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
shape = SubResource( 1 )
shape = SubResource("1")