Jump to content

i'm just starting to play and enjoy with Leadwerks!


Charrua
 Share

Recommended Posts

not all is work!

 

 

Here the code that does the magic:

 

Create a sphere on start

 

function Script:Start()
--as this script is attached to the camera, here is a good place to
--set a global camera variable and so, it can be used in any other script of this project.
camera=self.entity
--Create a sphere to indicate where the pick hits
 self.picksphere = Model:Sphere()
 self.picksphere:SetColor(1.0,0.0,0.0)
 self.picksphere:SetPickMode(0)
 self.picksphere:SetScale(pickradius*2.0)
 self.picksphere:Hide()
System:Print("fly.lua start")
end

 

on the update world function:

 

if appWindow:MouseHit(1) then
		 local pickinfo = PickInfo()
		 local p = appWindow:GetMousePosition()

--do a camera pick
--place a new instance of the picksphere ent at the picked position
--place a hinge joint to keep the sphere and the picked object together
		 if (camera:Pick(p.x,p.y,pickinfo,pickradius,true)) then
local newEnt = self.picksphere:Instance()
newEnt:SetPhysicsMode(Entity.RigidBodyPhysics)
newEnt:SetMass(10)
local shape = Shape:Sphere()
newEnt:SetShape(shape)
shape:Release()
newEnt:SetPosition(pickinfo.position)
local hingeVar = Joint:Slider(pickinfo.position.x, pickinfo.position.y, pickinfo.position.z, 0, 0, 0, pickinfo.entity, newEnt)
hingeVar:SetLimits(0,0)
hingeVar:EnableLimits()
newEnt:Show()
		 end
 end

 

a note about: appWindow

 

on app.lua, i declare this global variable and pass the window created there, so i can use it on any other script

 

here the modification of app.lua:

 

appWindow=nil --global variable, so fly.lua can reach and use the window created on start
function App:Start()

--Initialize Steamworks (optional)
--Steamworks:Initialize()

--Set the application title
self.title="MyGame"
--Create a window
self.window=Window:Create(self.title)
--self.window:HideMouse() --do not hide the mouse pointer
appWindow=self.window  --set the global variable appWindow with the window just created

--rest of the script/function as default

  • Upvote 5

Paren el mundo!, me quiero bajar.

Link to comment
Share on other sites

sliders will came late... and balls also

 

i'm still playing with hinges.

 

4 or 3 wheels: tricycle or car.. very elemental, with no control (until)

 

a couple of captures, on the editor, and running the code.

 

 

the video is uploading...

 

 

 

cars.png

 

cars1.png

  • Upvote 4

Paren el mundo!, me quiero bajar.

Link to comment
Share on other sites

I made a vehicle system once, it was super glitchy biggrin.png

I programmed the springs myself using a hing joint and applying force using scripts to keep it at a certain angle I'm sure there's got to be a better way to do it though.

Adjusting how much force was applied would adjust the spring stiffness, increasing force the more angle it was away from it's target angle.

Link to comment
Share on other sites

i'm using hinges only.

 

to get wheel rotation, simply read the current joint angle and set it to some value ahead, having motor enabled

speed is controlled by MotorSpeed

 

wheels are cylinders ... made by segments and so the whell gets jumping constantly and so, the vehicle goes slower that it should...

 

if you tell the camera to follow the vehicle, then you will see how unstable it is...

 

i'm not applying forces/torque, just MotorSpeed, Limits, Angle

 

also, to much or to less mass on the individual parts of the vehicle make it behave differently, bad/worse

 

i'm doing some code-clean-up, then i will post the scripts i'm using. Not sure if it is the correct way of doing things, but problably some one can point me in the right direction...

 

thank's for the comments

Paren el mundo!, me quiero bajar.

Link to comment
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.

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.

 Share

×
×
  • Create New...