Skip to content

Commit

Permalink
Merge pull request #17 from GREEN-CHAOS/main
Browse files Browse the repository at this point in the history
adds Parachute and enhances Camera
Nice next tiny update
  • Loading branch information
haennes authored Apr 30, 2021
2 parents bcdf2f3 + 8c1814e commit 14cfea2
Show file tree
Hide file tree
Showing 10 changed files with 251 additions and 16 deletions.
21 changes: 21 additions & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -58,6 +63,7 @@ _global_script_class_icons={
"Engine": "",
"FuelTank": "",
"GravityObject": "",
"Parachute": "",
"Part": "",
"PersonCamera": "",
"Player": "",
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions scenes/MainScene.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions scenes/Player/PersonCamera.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -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 )

Expand Down
12 changes: 11 additions & 1 deletion scenes/Rocket/Rocket.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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 )]

Expand All @@ -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 )
112 changes: 112 additions & 0 deletions scenes/RocketParts/Parachute/Parachute.tscn
Original file line number Diff line number Diff line change
@@ -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 )
5 changes: 3 additions & 2 deletions scripts/Player/3rdPersonCamera.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
46 changes: 36 additions & 10 deletions scripts/Rocket/DebugConfigureRocket.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var tank
var engine
var rcs
var rcs2
var parachute
var camera

func _ready():
Expand All @@ -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()

Expand All @@ -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):

Expand All @@ -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):
Expand All @@ -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)
Expand All @@ -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):
Expand All @@ -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)
2 changes: 1 addition & 1 deletion scripts/RocketParts/Engine/Engine.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
58 changes: 58 additions & 0 deletions scripts/RocketParts/Parachute/Parachute.gd
Original file line number Diff line number Diff line change
@@ -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)

Loading

0 comments on commit 14cfea2

Please sign in to comment.