Missile Movement and dV Capacity

Implemented Missile movement and acceleration via simple throttle (from 0.0 to 1.0) instructions. Each missile also has its own fuel given in dV (delta-V) and all thrusters turn and stay off when it reaches 0.

Known Issue:
The rotation thrusters do not turn off correctly when the dV runs out. Seems to be just a visual bug tho.
main
Peery 2 years ago
parent 9b91d2c8a9
commit 4068d504a5

@ -3,9 +3,39 @@ extends Spatial
onready var exhaust_node = $Exhaust;
const ACCEL = 0.1; #24.5; # Unit: m/s^2
const MAX_DV = 0.2;#3300.0; # Delta V in m/s
const MAX_TURN_RATE = 1.0; # Universal turn rate in °/s^2
var MISSILE_ID = "UNKNOWN";
var is_operational: bool = true; # if the missile is operational
var has_fuel: bool = true;
var turn_instruction: Vector3 = Vector3(0, 1, 0); # vector of (X, Y, Z) possible rotational thrust to apply (0.0 to 1.0 for full turn)
var thrust_instruction: float = 0.5; # throttle between 0.0 and 1.0 of available thrust to apply
var curr_rotation_vel: Vector3 = Vector3();
var curr_thrust: float = 0.0;
var curr_velocity: Vector3 = Vector3();
var curr_DV: float = MAX_DV;
var __curr_shader_param_cache = {};
func _set_thruster_thrust(node: MeshInstance, power):
#print("Node: ", node.name)
var MAX_POWER = 10;
if node.name in __curr_shader_param_cache:
if __curr_shader_param_cache[node.name] == power:
#print("Skipped shader edit");
return;
### DEBUG CODE
if node.name in __curr_shader_param_cache:
print("Editing "+node.name+" because "+str(__curr_shader_param_cache[node.name])+" != "+str(power)+" (old vs new)");
###
__curr_shader_param_cache[node.name] = power;
node.get_surface_material(0).set_shader_param("power", clamp(power, .0, MAX_POWER));
var particle_node: Particles = node.get_node("./Particles");
@ -20,81 +50,105 @@ func _set_thruster_thrust(node: MeshInstance, power):
# Set the visual main engine flare from 0.0 to 10.0
# 0.0 turns off all engine effects
func set_main_engine_thrust(power):
func set_main_engine_thrust(power: float):
var exhausts = exhaust_node.get_node("Main").get_children();
print("Changing main exhaust to: ", power);
#print("Changing main exhaust to: ", power);
for node in exhausts:
self._set_thruster_thrust(node, power);
# Set the visual rotational engine flare from -10.0 to 10.0
# Negative power visualizes downwards, Positive upwards and 0.0 turns all X thrusters off
func set_X_rotational_thrust(power):
var MAX_POWER = 10;
func set_X_rotational_thrust(power: float):
var up_rotation_thrusters = [exhaust_node.get_node("FrontThrusters/ThrusterBottom"), exhaust_node.get_node("RearThrusters/ThrusterTop")];
var down_rotation_thrusters = [exhaust_node.get_node("FrontThrusters/ThrusterTop"), exhaust_node.get_node("RearThrusters/ThrusterBottom")];
if power > 0.0:
print("Changing rotation thrust upwards to: ", power);
#print("Changing rotation thrust upwards to: ", power);
for node in up_rotation_thrusters:
self._set_thruster_thrust(node, power);
for node in down_rotation_thrusters:
self._set_thruster_thrust(node, 0.0);
elif power < 0.0:
print("Changing rotation thrust downwards to: ", power);
#print("Changing rotation thrust downwards to: ", power);
for node in down_rotation_thrusters:
self._set_thruster_thrust(node, -1 * power);
for node in up_rotation_thrusters:
self._set_thruster_thrust(node, 0.0);
else:
print("Turning X rotation thrusters off");
#print("Turning X rotation thrusters off");
for node in up_rotation_thrusters+down_rotation_thrusters:
self._set_thruster_thrust(node, 0.0);
# Set the visual rotational engine flare from -10.0 to 10.0
# Negative power visualizes left, Positive right and 0.0 turns all Y thrusters off
func set_Y_rotational_thrust(power):
func set_Y_rotational_thrust(power: float):
var MAX_POWER = 10;
var left_rotation_thrusters = [exhaust_node.get_node("FrontThrusters/ThrusterLeft"), exhaust_node.get_node("RearThrusters/ThrusterRight")];
var right_rotation_thrusters = [exhaust_node.get_node("FrontThrusters/ThrusterRight"), exhaust_node.get_node("RearThrusters/ThrusterLeft")];
if power > 0.0:
print("Changing rotation thrust right to: ", power);
#print("Changing rotation thrust right to: ", power);
for node in right_rotation_thrusters:
self._set_thruster_thrust(node, power);
for node in left_rotation_thrusters:
self._set_thruster_thrust(node, 0.0);
elif power < 0.0:
print("Changing rotation thrust left to: ", power);
#print("Changing rotation thrust left to: ", power);
for node in left_rotation_thrusters:
self._set_thruster_thrust(node, -1 * power);
for node in right_rotation_thrusters:
self._set_thruster_thrust(node, 0.0);
else:
print("Turning Y rotation thrusters off");
#print("Turning Y rotation thrusters off");
for node in right_rotation_thrusters+left_rotation_thrusters:
self._set_thruster_thrust(node, 0.0);
func _ready():
set_main_engine_thrust(5.0);
set_X_rotational_thrust(10.0);
set_Y_rotational_thrust(10.0);
var time_passed = 0.0;
var curr_rot_power = 10.0;
var curr_main_power = 0.0;
func _ready():
set_main_engine_thrust(0.0);
set_X_rotational_thrust(0.0);
set_Y_rotational_thrust(0.0);
var timer = 0.0;
func _physics_process(delta):
time_passed += delta;
timer -= delta;
if time_passed > 1:
print("Setting rotation X to 5.0");
set_X_rotational_thrust(curr_rot_power);
set_Y_rotational_thrust(curr_rot_power);
set_main_engine_thrust(curr_main_power);
curr_rot_power *= -1;
curr_main_power += 1;
if curr_main_power > 10.0:
curr_main_power = 0.0;
time_passed = 0.0;
if not self.has_fuel or not self.is_operational:
if timer <= 0.0:
set_main_engine_thrust(0.0);
set_X_rotational_thrust(0.0);
set_Y_rotational_thrust(0.0); # TODO fix issue with turning off rotational thrusters
timer = 1.0
else:
if timer <= 0.0:
set_X_rotational_thrust(lerp(0.0, 10.0, turn_instruction.x));
set_Y_rotational_thrust(lerp(0.0, 10.0, turn_instruction.y));
set_main_engine_thrust(lerp(0.0, 10.0, thrust_instruction));
self.transform = self.transform.orthonormalized();
### DEBUG CODE
print("Rotation: "+str(self.curr_rotation_vel)+", Velocity: "+str(self.curr_velocity)+" Remeining dV: "+str(self.curr_DV));
###
timer = 1.0;
self.curr_rotation_vel += turn_instruction * Vector3(MAX_TURN_RATE, MAX_TURN_RATE, 0.0) * delta;
self.curr_thrust = thrust_instruction * ACCEL * delta;
self.curr_velocity += self.global_transform.basis.z * self.curr_thrust * -1;
self.curr_DV -= curr_thrust;
if curr_DV <= 0.0:
print("Missile "+MISSILE_ID+" has run out of fuel!");
self.has_fuel = false;
if self.curr_rotation_vel.length() > 0.0:
self.rotate_x(deg2rad(self.curr_rotation_vel.x));
self.rotate_y(deg2rad(self.curr_rotation_vel.y));
if self.curr_velocity.length() > 0.0:
#self.translate(self.curr_velocity);
self.global_translate(self.curr_velocity);

@ -119,18 +119,18 @@ shader_param/power = 1.0
script = ExtResource( 3 )
[node name="missile body" parent="." index="0"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.851097 )
transform = Transform( -1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, 0, -0.851097 )
material/0 = SubResource( 2 )
[node name="RigidBody" type="RigidBody" parent="." index="1"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.688615 )
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -1.71819 )
[node name="CollisionShape" type="CollisionShape" parent="RigidBody" index="0"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.371096 )
shape = SubResource( 1 )
[node name="Exhaust" type="Spatial" parent="." index="2"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -5.74946 )
transform = Transform( -1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, 0, 4.04751 )
[node name="Main" type="Spatial" parent="Exhaust" index="0"]

@ -33,10 +33,7 @@ script = ExtResource( 3 )
mesh = SubResource( 3 )
[node name="missile" parent="entities" instance=ExtResource( 4 )]
transform = Transform( 0.965223, 0, -0.261431, 0.176115, 0.739043, 0.65023, 0.193209, -0.673658, 0.713342, -2.93378, 8.26498, -11.9562 )
[node name="missile2" parent="entities" instance=ExtResource( 4 )]
transform = Transform( 0.881144, 0.176115, -0.438829, -0.436702, 0.65898, -0.612404, 0.181326, 0.731252, 0.657566, 9.71882, 6.0822, -4.97612 )
transform = Transform( -1, 0, -8.74229e-08, 0, 1, 0, 8.74228e-08, 0, -1, 2.0179, 4.1307, -11.9562 )
[node name="lighting" type="Node" parent="."]
@ -50,5 +47,5 @@ light_color = Color( 0.411765, 0.854902, 0.92549, 1 )
light_energy = 0.2
[node name="Camera" type="Camera" parent="."]
transform = Transform( -0.916363, 0.11884, -0.382304, 0, 0.954927, 0.296842, 0.400349, 0.272015, -0.875059, -4.41776, 10.7973, -27.9208 )
transform = Transform( -1, -1.42109e-14, -8.74228e-08, -6.25476e-08, 0.698653, 0.715461, 6.10781e-08, 0.715461, -0.698653, 2.0179, 16.7567, -19.9562 )
current = true

Loading…
Cancel
Save