Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

how to control a spacecraft with Lua ?

Recommended Posts

I'm more an artist than a coder and was looking at the FPS Script to get a rough idea but can't figure out how to control a spacecraft.


Basically :


orbit around the spacecraft on key toggle


W - accelerate

S - slow down / backward

A / D - roll

Mouse - yaw / pitch


with zero gravity


If there is already a tutorial that I missed (YouTube ?) let me know, otherwise any help most welcome

Link to post
Share on other sites

u need from Window class :KeyDown(Key.A)

and for self.entity:

any movement functions or maybe physics.

zero gravity with physics :SetGravityMode(false)




non physics

with Translate u can put it up and down,forwand & backwards, left & right

with Turn pitch, yaw and roll


not global = local means along/around the objext axis x,y,z.

Link to post
Share on other sites

From one of my projects called Lunar lander, very simple but easy to adapt and add more.


Give you model Character controller and some mass.


function Script:Start()
  self.rot = Vec3(0,0,0)
self.input = 0   

function Script:UpdatePhysics()

local v = self.entity:GetVelocity()
local turnspeed=1

if v.y <= 4 then
  if (App.window:KeyDown(Key.Space)) then self.entity:AddForce(0,0.5*Time:GetSpeed(),0)
  else if v.y >= -1 then self.entity:AddForce(0,-0.05*Time:GetSpeed(),0) end

if (App.window:KeyDown(Key.W)) then self.input = 0.5 end
if (App.window:KeyDown(Key.S)) then self.input = -0.5 end
if (App.window:KeyDown(Key.Q)) then self.rot.y=self.rot.y-turnspeed*Time:GetSpeed() end 
if (App.window:KeyDown(Key.E)) then self.rot.y=self.rot.y+turnspeed*Time:GetSpeed() end



Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...