Imagine a cube with 4 thrusters on each face, like on a small space-capsule.
These generate thrust in 12 directions (Forward, Backward, Left, Right, Up, Down, +Yaw, -Yaw, +Pitch, -Pitch, +Roll, -Roll)
Thrust for each direction is calculated and (should be) implemented each frame.
My rotations (Yaw, Pitch and Roll) work like a charm ... but I'm too stupid to integrate the linear thrust (generated local to object's orientation) into a single global translation for my object.
Please help!
extends KinematicBody
var Decay:float = 2.0;
var CurrDecay:float = 0.0;
var ThrustX:float = 0.0;
var ThrustY:float = 0.0;
var ThrustZ:float = 0.0;
var ThrustMax:float = 50.0;#Meters/Second
var RotateY:float = 0.0;
var RotateX:float = 0.0;
var RotateZ:float = 0.0;
var RotateMax:float = 10.0;#Degrees/Second
onready var Velocity:Vector3 = transform.origin;
func _process(delta):
if Input.is_action_pressed("Shift"):
if Input.is_action_pressed("Pitch+"):
RotateX -= (RotateMax-abs(RotateX)) * delta;
if Input.is_action_pressed("Pitch-"):
RotateX += (RotateMax-RotateX) * delta;
if Input.is_action_pressed("ThrustLeft"):
ThrustX -= (ThrustMax-abs(ThrustX)) * delta;
if Input.is_action_pressed("ThrustRight"):
ThrustX += (ThrustMax-ThrustX) * delta;
if Input.is_action_pressed("ThrustUp"):
ThrustY += (ThrustMax-ThrustY) * delta;
if Input.is_action_pressed("ThrustDown"):
ThrustY -= (ThrustMax-abs(ThrustY)) * delta;
else:
if Input.is_action_pressed("ThrustFront"):
ThrustZ -= (ThrustMax-abs(ThrustZ)) * delta;
if Input.is_action_pressed("ThrustBack"):
ThrustZ += (ThrustMax-ThrustZ) * delta;
if Input.is_action_pressed("Yaw+"):
RotateY += (RotateMax-RotateY) * delta;
if Input.is_action_pressed("Yaw-"):
RotateY -= (RotateMax-abs(RotateY)) * delta;
if Input.is_action_pressed("Roll+"):
RotateZ -= (RotateMax-abs(RotateZ)) * delta;
if Input.is_action_pressed("Roll-"):
RotateZ += (RotateMax-RotateZ) * delta;
#DAMPEN
CurrDecay = delta*Decay;
RotateX = lerp(RotateX,0.0,CurrDecay);
RotateY = lerp(RotateY,0.0,CurrDecay);
RotateZ = lerp(RotateZ,0.0,CurrDecay);
ThrustX = lerp(ThrustX,0.0,CurrDecay);
ThrustY = lerp(ThrustY,0.0,CurrDecay);
ThrustZ = lerp(ThrustZ,0.0,CurrDecay);
#EXECUTE
rotate_object_local(Vector3.FORWARD,deg2rad(RotateZ));
rotate_object_local(Vector3.RIGHT,deg2rad(RotateX));
rotate_object_local(Vector3.UP,deg2rad(RotateY));
#CRAPPY MISGUIDED LOW-IQ ATTEMPT OF TRANSLATION:
var ThrustVector = Vector3(ThrustX,ThrustY,ThrustZ);# ???
Velocity = Velocity * ThrustVector;# ???
global_translate(Velocity);# ???
#move_and_collide(Velocity);# ???
#translate(Velocity);# ???