Jump to content
domi

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

Share this post


Link to post

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

and for self.entity:

any movement functions or maybe physics.

zero gravity with physics :SetGravityMode(false)

 

http://www.leadwerks.com/werkspace/page/documentation/_/command-reference/entity/

 

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.

Share this post


Link to post

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.entity:SetGravityMode(false)
  self.rot = Vec3(0,0,0)
self.input = 0   
end

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
  end
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

self.entity:SetInput(self.rot.y,0,self.input,0,false,1)

end

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
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...