diff --git a/project.godot b/project.godot index 0ec4445..3e20de5 100644 --- a/project.godot +++ b/project.godot @@ -24,6 +24,11 @@ _global_script_classes=[ { "language": "GDScript", "path": "res://scripts/GravityObject/GravityObject.gd" }, { +"base": "Part", +"class": "Parachute", +"language": "GDScript", +"path": "res://scripts/RocketParts/Parachute/Parachute.gd" +}, { "base": "GravityObject", "class": "Part", "language": "GDScript", @@ -58,6 +63,7 @@ _global_script_class_icons={ "Engine": "", "FuelTank": "", "GravityObject": "", +"Parachute": "", "Part": "", "PersonCamera": "", "Player": "", @@ -201,6 +207,21 @@ rcs_down={ "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":16777237,"unicode":0,"echo":false,"script":null) ] } + +parachute_open={ +"deadzone": 0.5, +"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":66,"unicode":0,"echo":false,"script":null) + ] +} +parachute_cut={ +"deadzone": 0.5, +"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":78,"unicode":0,"echo":false,"script":null) + ] +} +parachute_load={ +"deadzone": 0.5, +"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":77,"unicode":0,"echo":false,"script":null) + scroll_in={ "deadzone": 0.5, "events": [ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"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":4,"pressed":false,"doubleclick":false,"script":null) diff --git a/scenes/MainScene.tscn b/scenes/MainScene.tscn index f1ce93f..85a95e3 100644 --- a/scenes/MainScene.tscn +++ b/scenes/MainScene.tscn @@ -23,13 +23,13 @@ script = ExtResource( 1 ) multimesh = SubResource( 2 ) [node name="Rocket" parent="." instance=ExtResource( 2 )] -transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 6.80425, 13.0594 ) +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 57.5841, 13.0594 ) [node name="StaticBody" type="StaticBody" parent="."] transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -2.23989, 0 ) [node name="MeshInstance" type="MeshInstance" parent="StaticBody"] -transform = Transform( 50, 0, 0, 0, 1, 0, 0, 0, 50, 0, 0, 0 ) +transform = Transform( 50, 0, 0, 0, 1, 0, 0, 0, 50, 0, 0.334449, 0 ) mesh = SubResource( 3 ) material/0 = null diff --git a/scenes/Player/PersonCamera.tscn b/scenes/Player/PersonCamera.tscn index 28b4e34..a317453 100644 --- a/scenes/Player/PersonCamera.tscn +++ b/scenes/Player/PersonCamera.tscn @@ -4,6 +4,7 @@ [node name="PersonCamera" type="SpringArm"] transform = Transform( 1, -0.000510735, 0.000318044, 0.000510832, 1, -0.000278954, -0.00031789, 0.00027913, 1, 0, 0, 0 ) +collision_mask = 0 spring_length = 20.0 script = ExtResource( 1 ) diff --git a/scenes/Rocket/Rocket.tscn b/scenes/Rocket/Rocket.tscn index de64053..e0505d6 100644 --- a/scenes/Rocket/Rocket.tscn +++ b/scenes/Rocket/Rocket.tscn @@ -5,6 +5,7 @@ [ext_resource path="res://scenes/RocketParts/FuelTanks/FuelTank.tscn" type="PackedScene" id=3] [ext_resource path="res://scenes/Player/PersonCamera.tscn" type="PackedScene" id=4] [ext_resource path="res://scenes/RocketParts/RCSThruster/RCSThrusterTemplate.tscn" type="PackedScene" id=5] +[ext_resource path="res://scenes/RocketParts/Parachute/Parachute.tscn" type="PackedScene" id=6] [sub_resource type="Curve3D" id=1] _data = { @@ -19,13 +20,13 @@ script = ExtResource( 2 ) curve = SubResource( 1 ) [node name="Engine" parent="." instance=ExtResource( 1 )] +mass = 152.73 custom_integrator = true affected_by_gravity = false [node name="Tank" parent="." instance=ExtResource( 3 )] transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2, 0 ) custom_integrator = true -affected_by_gravity = false [node name="PersonCamera" parent="Tank" instance=ExtResource( 4 )] @@ -40,3 +41,12 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 1.5, 1, 0 ) mass = 0.01 custom_integrator = true affected_by_gravity = false + +[node name="RCS3" parent="." instance=ExtResource( 5 )] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 1.5, 1, 0 ) +mass = 0.01 +custom_integrator = true +affected_by_gravity = false + +[node name="Parachute" parent="." instance=ExtResource( 6 )] +transform = Transform( 0.999999, 0.00171042, 0, -0.00171042, 0.999999, 0, 0, 0, 1, 0, 3.819, 0 ) diff --git a/scenes/RocketParts/Parachute/Parachute.tscn b/scenes/RocketParts/Parachute/Parachute.tscn new file mode 100644 index 0000000..6a63c8f --- /dev/null +++ b/scenes/RocketParts/Parachute/Parachute.tscn @@ -0,0 +1,112 @@ +[gd_scene load_steps=7 format=2] + +[ext_resource path="res://scripts/RocketParts/Parachute/Parachute.gd" type="Script" id=1] + +[sub_resource type="CylinderMesh" id=1] + +[sub_resource type="CylinderMesh" id=2] + +[sub_resource type="CylinderMesh" id=3] + +[sub_resource type="Animation" id=4] +resource_name = "parachute_cut" + +[sub_resource type="Animation" id=5] +length = 3.0 +tracks/0/type = "transform" +tracks/0/path = NodePath("Parachute") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/keys = PoolRealArray( ) +tracks/1/type = "bezier" +tracks/1/path = NodePath("Parachute:translation:x") +tracks/1/interp = 1 +tracks/1/loop_wrap = true +tracks/1/imported = false +tracks/1/enabled = true +tracks/1/keys = { +"points": PoolRealArray( 0, -0.25, 0, 0.25, 0, 0, -0.25, 0, 0.25, 0, 0, -0.25, 0, 0.25, 0, 0, -0.25, 0, 0.25, 0, 0, -0.25, 0, 0.25, 0 ), +"times": PoolRealArray( 0, 0.1, 0.2, 0.3, 3 ) +} +tracks/2/type = "bezier" +tracks/2/path = NodePath("Parachute:translation:y") +tracks/2/interp = 1 +tracks/2/loop_wrap = true +tracks/2/imported = false +tracks/2/enabled = true +tracks/2/keys = { +"points": PoolRealArray( 0, -0.25, 0, 0.25, 0, 1, -0.25, 0, 0.25, 0, 2, -0.25, 0, 0.25, 0, 2.3, -0.25, 0, 0.25, 0, 15.4056, -0.25, 0, 0.25, 0 ), +"times": PoolRealArray( 0, 0.1, 0.2, 0.3, 3 ) +} +tracks/3/type = "bezier" +tracks/3/path = NodePath("Parachute:translation:z") +tracks/3/interp = 1 +tracks/3/loop_wrap = true +tracks/3/imported = false +tracks/3/enabled = true +tracks/3/keys = { +"points": PoolRealArray( 0, -0.25, 0, 0.25, 0, 0, -0.25, 0, 0.25, 0, 0, -0.25, 0, 0.25, 0, 0, -0.25, 0, 0.25, 0, 0, -0.25, 0, 0.25, 0 ), +"times": PoolRealArray( 0, 0.1, 0.2, 0.3, 3 ) +} +tracks/4/type = "bezier" +tracks/4/path = NodePath("Parachute:scale:x") +tracks/4/interp = 1 +tracks/4/loop_wrap = true +tracks/4/imported = false +tracks/4/enabled = true +tracks/4/keys = { +"points": PoolRealArray( 1, -0.25, 0, 0.25, 0, 1, -0.25, 0, 0.25, 0, 1.5, -0.25, 0, 0.25, 0, 20, -0.25, 0, 0.25, 0 ), +"times": PoolRealArray( 0, 0.1, 0.3, 3 ) +} +tracks/5/type = "bezier" +tracks/5/path = NodePath("Parachute:scale:y") +tracks/5/interp = 1 +tracks/5/loop_wrap = true +tracks/5/imported = false +tracks/5/enabled = true +tracks/5/keys = { +"points": PoolRealArray( 1, -0.25, 0, 0.25, 0, 1, -0.25, 0, 0.25, 0, 1, -0.25, 0, 0.25, 0, 1, -0.25, 0, 0.25, 0 ), +"times": PoolRealArray( 0, 0.1, 0.3, 3 ) +} +tracks/6/type = "bezier" +tracks/6/path = NodePath("Parachute:scale:z") +tracks/6/interp = 1 +tracks/6/loop_wrap = true +tracks/6/imported = false +tracks/6/enabled = true +tracks/6/keys = { +"points": PoolRealArray( 1, -0.25, 0, 0.25, 0, 1, -0.25, 0, 0.25, 0, 1.5, -0.25, 0, 0.25, 0, 20, -0.25, 0, 0.25, 0 ), +"times": PoolRealArray( 0, 0.1, 0.3, 3 ) +} + +[node name="Parachute" type="RigidBody"] +script = ExtResource( 1 ) +housing = NodePath("House") +parachute = NodePath("Parachute") +cap = NodePath("Cap") +parachute_animation = NodePath("AnimationPlayer") +offset = NodePath("House") + +[node name="House" type="MeshInstance" parent="."] +transform = Transform( 2, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0 ) +mesh = SubResource( 1 ) +skeleton = NodePath("") +material/0 = null + +[node name="Cap" type="MeshInstance" parent="."] +transform = Transform( 1, 0, 0, 0, 0.2, 0, 0, 0, 1, 0, 1.14392, 0 ) +mesh = SubResource( 2 ) +material/0 = null + +[node name="Parachute" type="MeshInstance" parent="."] +transform = Transform( 20, 0, 0, 0, 1, 0, 0, 0, 20, 0, 15.4056, 0 ) +mesh = SubResource( 3 ) +material/0 = null + +[node name="Joint" type="Generic6DOFJoint" parent="."] + +[node name="AnimationPlayer" type="AnimationPlayer" parent="."] +anims/parachute_cut = SubResource( 4 ) +anims/parachute_open = SubResource( 5 ) diff --git a/scripts/Player/3rdPersonCamera.gd b/scripts/Player/3rdPersonCamera.gd index 493d53f..86851c8 100644 --- a/scripts/Player/3rdPersonCamera.gd +++ b/scripts/Player/3rdPersonCamera.gd @@ -5,6 +5,7 @@ extends SpringArm enum CameraMode { FIRST_PERSON , _3RD_PERSON = 2 } # _ is needed other wise it gets confused var scroll_speed = 0.1 #move this to CameraData +var mouse_sensitivity = Vector2(0.1,0.1) var spring_length_last = spring_length var current_camera_mode = CameraMode.FIRST_PERSON @@ -36,8 +37,8 @@ func _input_pass_through(event : InputEventMouse): if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED: if event is InputEventMouseMotion: - rotation_degrees.x = clamp(rotation_degrees.x - event.relative.y*0.1,-90,90) - rotation_degrees.y -= event.relative.x*0.1 + rotation_degrees.x = clamp(rotation_degrees.x - event.relative.y*mouse_sensitivity.y,-90,90) + rotation_degrees.y -= event.relative.x*mouse_sensitivity.x else: if event.is_action_pressed("scroll_in"): spring_length -= scroll_speed diff --git a/scripts/Rocket/DebugConfigureRocket.gd b/scripts/Rocket/DebugConfigureRocket.gd index 20ea092..45b7051 100644 --- a/scripts/Rocket/DebugConfigureRocket.gd +++ b/scripts/Rocket/DebugConfigureRocket.gd @@ -7,6 +7,7 @@ var tank var engine var rcs var rcs2 +var parachute var camera func _ready(): @@ -16,6 +17,7 @@ func _ready(): engine = rocket.get_node("Engine") rcs = rocket.get_node("RCS") rcs2 = rocket.get_node("RCS2") + parachute = rocket.get_node("Parachute") camera = tank.get_node("PersonCamera") _link_parts() @@ -31,7 +33,9 @@ func _link_parts(): rcs2.get_node("Joint").set_node_a(rcs2.get_path()) rcs2.get_node("Joint").set_node_b(engine.get_path()) rocket.get_node("Engine").connected_tank = tank - + parachute.get_node("Joint").set_node_a(parachute.get_path()) + parachute.get_node("Joint") .set_node_b(engine.get_path()) + func _input(event): @@ -47,6 +51,20 @@ func _input(event): if event.is_action_pressed("fire_engine"): engine.toggle_engine() print("fire_engine") + + if event.is_action_pressed("parachute_open",true): + parachute.parachute_open() + + if event.is_action_pressed("parachute_cut", true): + parachute.parachute_cut() + + if event.is_action_pressed("parachute_load", true): + parachute.parachute_load() + + if event.is_action_pressed("rcs_backward",true): + rcs.fire_thrusters_global(Vector3.BACK,1.0) + rcs2.fire_thrusters_global(Vector3.BACK,1.0) + print("rcs_backwards") if rcs_on: if event.is_action_pressed("rcs_backward",true): @@ -60,6 +78,7 @@ func _input(event): print("rcs_forwards") + elif event.is_action_pressed("rcs_left",true): rcs.fire_thrusters_global(Vector3.LEFT,1.0) rcs2.fire_thrusters_global(Vector3.RIGHT,1.0) @@ -75,16 +94,17 @@ func _input(event): rcs.fire_thrusters_global(Vector3.UP,1.0) rcs2.fire_thrusters_global(Vector3.DOWN,1.0) print("rcs_up") + + elif event.is_action_pressed("rcs_down",true): + rcs.fire_thrusters_global(Vector3.DOWN,1.0) + rcs2.fire_thrusters_global(Vector3.UP,1.0) + print("rcs_down") - elif event.is_action_pressed("rcs_down",true): - rcs.fire_thrusters_global(Vector3.DOWN,1.0) - rcs2.fire_thrusters_global(Vector3.UP,1.0) - print("rcs_down") - - else: - rcs.fire_thrusters_global(Vector3.ZERO,1.0) - rcs2.fire_thrusters_global(Vector3.ZERO,1.0) - #print("rcs_reset") + else: + rcs.fire_thrusters_global(Vector3.ZERO,1.0) + rcs2.fire_thrusters_global(Vector3.ZERO,1.0) + #print("rcs_reset") + else: if event.is_action_pressed("pitch_forward",true): @@ -106,3 +126,9 @@ func change_mouse_mode(): Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) else: Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) + +func split_mesh(node, _mass : int): + var body = Part.new() + body.mass = _mass + body.add_child(node) + rocket.add_child(node) diff --git a/scripts/RocketParts/Engine/Engine.gd b/scripts/RocketParts/Engine/Engine.gd index 0fd442a..eb86495 100644 --- a/scripts/RocketParts/Engine/Engine.gd +++ b/scripts/RocketParts/Engine/Engine.gd @@ -43,7 +43,7 @@ func _consume_fuel(): func _integrate_forces(state): _integrate_engine_thrust(state) - add_central_force(Vector3.DOWN*2) + add_central_force(Vector3.DOWN*mass) func tilt_enine(direction : Vector2): var rotation_clamped_x = clamp(rotation_degrees.x + direction.x,min_tilt.x,max_tilt.x) diff --git a/scripts/RocketParts/Parachute/Parachute.gd b/scripts/RocketParts/Parachute/Parachute.gd new file mode 100644 index 0000000..3bb3aa4 --- /dev/null +++ b/scripts/RocketParts/Parachute/Parachute.gd @@ -0,0 +1,58 @@ +class_name Parachute +extends Part + +enum ParachuteState { READY, DEPLOYED = 2, EXPLOYED = 3, } +export(NodePath) var housing +export(NodePath) var parachute +export(NodePath) var cap +export(NodePath) var parachute_animation +export(NodePath) var offset +export var air_thickness = 3 +var parachute_state +var density = 1.23 +var drag_coefficient = 0.5 +var parachute_area = 1 +var force_length = 1 +var cw = 2.1 + + +func parachute_open(): + if parachute_state == ParachuteState.READY: + parachute.visible = true + housing.visible = false + cap.visible = false + parachute_animation.play("parachute_open") + parachute_state = ParachuteState.DEPLOYED + parachute_area = parachute.scale.x * parachute.scale.z * PI + else: print("Parachute not available") + +func parachute_cut(): + if parachute_state == ParachuteState.DEPLOYED: + parachute_state = ParachuteState.EXPLOYED + else: print("Parachute Cut is not available") + +func parachute_load(): + if parachute_state == ParachuteState.EXPLOYED: + parachute_state = ParachuteState.DEPLOYED + else: print("No parachute to load") + +func _ready(): + housing = get_node(housing) + parachute = get_node(parachute) + cap = get_node(cap) + parachute_animation = get_node(parachute_animation) + offset = get_node(offset) + parachute.visible = false + parachute_state = ParachuteState.READY + +func _integrate_forces(state): + _integrate_parachute_forces(state) + +func _integrate_parachute_forces(state): + if parachute_state == ParachuteState.DEPLOYED: + var v = linear_velocity.length() + var forceMagnitude = 0.5 * drag_coefficient * parachute_area * v * v + var forceDirection = -linear_velocity.normalized() + var forceAppliedLocation = offset.translation + add_force(forceMagnitude * forceDirection, forceAppliedLocation) + diff --git a/scripts/RocketParts/parts.gd b/scripts/RocketParts/parts.gd index 42af94f..63d4e2f 100644 --- a/scripts/RocketParts/parts.gd +++ b/scripts/RocketParts/parts.gd @@ -16,3 +16,9 @@ func scale_childs(scale : Vector3) -> void: get_child(i).scale = scale get_child(i).translation *= scale +#func split_mesh(node, _mass : int): + #var body = Part.new() + #body.mass = _mass + #body.add_child(node) + #get_parrent().add_child(node) +