Jump to content

Recommended Posts

Posted

Hey, Im ashley (first post so better intraduce myself) and no im not a girl (I'm aware that Ashley is a girls name in America). Housekeeping aside, I've been experimenting with leadwerks (after only buying it 2 hours ago) and I'm finding it pretty triky to get this basic script to work. All I want is for the cube to move when I press the W key.

So, this is my script (which is attached to a entity cube):


player = Vec3(0,0,0)
function Script:Start()
-- housekeeping, init type function always needs to be there else I get cringie
end
function Script:WorldUpdate()
--Update function
if App.window:KeyDown(Key.W) then
player:Move(1,0,0)
end
end

 

any help and a little exsplnation would be awsome (I did know that the documentation was as bad as facebooks' but I still tryed to use it as much as possible along side the scripts that come with the engine, so I am trying >.< )

 

EDIT: I have

 player = Vec3(0,0,0) 

there because it makes more sence then just running

 Move(x,y,z)

. I understand if someone facepalms becuase there's no reason for it to be there, but its just one of the many variations of code I have tryied. ALSO: sorry about spelling, For somereason firefox isn't picking up spell check in this wysiwyg Editor -.-

 

SOLVED:

Ok, so I managed to solve the issue. It turns out

 Script:WorldUpdate

Isn't what I thought it was (basic Update function) So Insted, I have used

 Script:UpdatePhysics

. From there I changed a few things and also learnt that I could reference the current entity with

 self.entity 

. So all together I have managed to pull this together:

function Script:Start()
-- basic init
end

function Script:UpdatePhysics()
--Update function
if window:KeyDown(Key.W) then
self.entity:Move(1,0,0)
end
end

 

Its incredably basic, and I feel pretty stupid but I was pretty stumped. Hopefully new programmers can use this as a basic example for movment.

Posted

player in your script is just a vector (it's just a 3d point in space). It's not a cube. It has no visual to it.

Ahh I see, I thought it allowed me to dedicate a varible to the cube's current Vector Points. Now I know it just creates one, thanks ^.^

Also, how would I move the object? I've tryed

 self:Move() 

and just

 Move() 

but nothing seems to work.

Posted

self.entity:Move()

 

self.entity refers to whatever entity the script is attached to. It could be a model, camera, pivot, csg, light, etc. it's a special variable that Leadwerks creates and assigns for you.

  • Upvote 1

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.

×
×
  • Create New...