lildragn Posted January 17, 2014 Share Posted January 17, 2014 Hiya, just purchased Leadwerks and I'm excited to get going, but being new to both the engine and LUA means a lot of growin pains, so I'm asking the helpful community here for some help to get started. I'm focused on creating a 2.5d prototype and would like to start very slow, first thing I would love to know is how can I move a character with WASD or game pad with the ability to run & jump... No animations at this point. I'll start a thread later to document my progress for myself and others who are heading the same direction. Thx Quote Link to comment Share on other sites More sharing options...
codeape Posted January 17, 2014 Share Posted January 17, 2014 This could possibly be of help: Quote Link to comment Share on other sites More sharing options...
lildragn Posted January 17, 2014 Author Share Posted January 17, 2014 Thx! I did look at this earlier, but it's confusing for a beginner like me since he's using an existing script. I'm sure someone here can show a very basic method for users such as myself to get familiar. I'll keep trying though, I'll see if I can strip some of the code out myself. Quote Link to comment Share on other sites More sharing options...
shadmar Posted January 17, 2014 Share Posted January 17, 2014 You could take a look at Scripts/Objects/Cameras/3rdPersonFollow.lua Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB Link to comment Share on other sites More sharing options...
AggrorJorn Posted January 18, 2014 Share Posted January 18, 2014 Have a look at this command. The script below uses the example from that page but only applies movement on the X axis. function App:Start() --Create a window self.window = Window:Create() self.context = Context:Create(self.window) self.world = World:Create() local camera = Camera:Create() camera:SetRotation(35,0,0) camera:Move(0,0,-8) local light = DirectionalLight:Create() light:SetRotation(35,35,0) --Enable navmesh debugging camera:SetDebugNavigationMode(true) --Create the ground local ground = Model:Box(10,1,10) ground:SetPosition(0,-0.5,0) ground:SetColor(0.0,0.25,0.0) --Create a shape local shape = Shape:Box(0,0,0, 0,0,0, 10,1,10) ground:SetShape(shape) shape:Release() --Create a model --This is an obstacle the player will walk around self.entity = Model:Box(1,1,3) self.entity:SetColor(0.0,0.0,1.0) self.entity:SetPosition(0,5,0) self.entity:SetMass(1) --Create a shape local shape = Shape:Box(0,0,0,0,0,0,1,1,3) self.entity:SetShape(shape) shape:Release() --Enable navigation obstacles ground:SetNavigationMode(true) self.entity:SetNavigationMode(true) --Create a character self.player = Pivot:Create() local visiblecapsule = Model:Cylinder(16,self.player) visiblecapsule:SetScale(1,2,1) visiblecapsule:SetPosition(0,1,0) self.player:SetPosition(-4,0,0) self.player:SetMass(1) self.player:SetPhysicsMode(Entity.CharacterPhysics) return true end function App:Loop() if self.window:Closed() or self.window:KeyHit(Key.Escape) then return false end Time:Update() local strafe = ((self.window:KeyDown(Key.Right)and 1 or 0) - (self.window:KeyDown(Key.Left) and 1 or 0))*4 self.player:SetInput(strafe,0,0) self.world:Update() self.world:Render() self.context:Sync() return true end Quote Link to comment Share on other sites More sharing options...
Tim Shea Posted January 18, 2014 Share Posted January 18, 2014 Thx! I did look at this earlier, but it's confusing for a beginner like me since he's using an existing script. I'm sure someone here can show a very basic method for users such as myself to get familiar. I'll keep trying though, I'll see if I can strip some of the code out myself. Unfortunately this isn't something that can be done "very basic" and from scratch. There are several, moderately complex components involved in developing almost any kind of three dimensional character control scheme. Think of it like cooking, prepackaged stuff will make it easy, but has to hide some of the detail. Quote Link to comment Share on other sites More sharing options...
lildragn Posted January 19, 2014 Author Share Posted January 19, 2014 Yeah this is going to take some work, especially for me to understand the way Lua works. I usually have no problems experimenting with new languages, but looking at the script you posted Aggror, it actually looks like a self contained scene if you know what I mean? It creates everything in the scene, I just really want to have a script that I place on an object/character and have it translate/move around with WASD. Then I can build on that. Ok so if I were to use the script you posted Aggror, how do I implement it? Doesn't appear to be a script to place on an existing model.... really confused here. >_> Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted January 19, 2014 Share Posted January 19, 2014 The script above is just an example of how the code would look like. Of course if you want to it be a little script that you can simply attach, it will need some work. The main scene script you see above has functions like Start() and Update(). Scripted objects have the same functions in them. This means that the code you have above can be partially copied in to an object script. I can make the script for you but that way you wont learn how to script. Here is my suggestion. Make a new lua script. When you make a new lua script, the editor fills in all the possible functions that are automatically called by the editor( functions like Start(), Update(), UpdatePhysics() etc) Try moving parts of the code from the script above, in to the Start and Update() function of your new script. If you get stuck there, post your script in a new topic and ask for help. This way you learn about object scripts and you will learn bit by bit how to do stuff in Lua. Quote Link to comment Share on other sites More sharing options...
lildragn Posted January 19, 2014 Author Share Posted January 19, 2014 Ok sounds good...thx Aggror Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted January 19, 2014 Share Posted January 19, 2014 Also, like Tim SHea says: this is not the lightest subject and you may not get the perfect character control behavior you want. Finetuning player controls can be a massive undertaking. Even the more experienced programmers have trouble getting the results they want for their game. My advice would also be: lower your standards a little bit on how your character control handle. It is something that helps me at least. Quote Link to comment Share on other sites More sharing options...
lildragn Posted January 19, 2014 Author Share Posted January 19, 2014 Yup I definitely understand this, it was the same in Unity as well, but unfortunately there's no prebuilt scripts for player movement aside from the FPS controller... I did try the TPS script but nothing showed in the Script fields. I'll actually try that again here. Quote Link to comment Share on other sites More sharing options...
lildragn Posted January 19, 2014 Author Share Posted January 19, 2014 Yeah I'm feeling really dumb here and I have to admit it's getting a bit frustrating... there really isn't a beginner friendly path here and as much as I want to learn I'm not sure where to look.... Having to strip out existing code and plug it in places isn't working like traditional scripting for me, I'm just basically trying to do something similar to this https://www.love2d.org/wiki/Tutorial:Hamster_Ball nothing fancy, just translate an object based on a key press, I simply want to drop a sphere on a plane and move it left, right, up and down. I thank you guys for dropping in and trying to help, but it really isn't clear for a new user. The tutorial I linked, is clear concise and I can read and understand it fully, it's also written in Lua but doesn't work 1:1 with Leadwerks. Quote Link to comment Share on other sites More sharing options...
MaD2ko0l Posted January 20, 2014 Share Posted January 20, 2014 Hi, I was trying to do a similar thing where by i was aiming to do a top down view and move the player via WASD. here is my code to do this: import "Scripts/Functions/ReleaseTableObjects.lua" Script.moveSpeed = 2.5 --float "Move Speed" Script.input={} Script.playerMovement = Vec3(0,0,0) function Script:Start() --Create a camera self.camera = Camera:Create() --Set the camera position self.camera:SetPosition(0,10,0) self.camera:SetRotation(90,0,0) --check to see if player has mass local mass = self.entity:GetMass() if self.entity:GetMass()==0 then Debug:Error("Player mass should be greater than 0.") end end function Script:UpdatePhysics() local window = Window:GetCurrent() --Player Movement local move = ((window:KeyDown(Key.W) and 1 or 0) - (window:KeyDown(Key.S) and 1 or 0))*4 local strafe = ((window:KeyDown(Key.D)and 1 or 0) - (window:KeyDown(Key.A) and 1 or 0))*4 local playerMovement = Vec3(0) playerMovement.x = move * self.moveSpeed playerMovement.z = strafe * self.moveSpeed self.entity:SetInput(0,playerMovement.x,playerMovement.z) --Move camera with player local playerPos = self.entity:GetPosition() local newCameraPos = self.camera:GetPosition() newCameraPos = Vec3(playerPos.x, 10, playerPos.z) self.camera:SetPosition(newCameraPos) end i have tried to document what i know to the best of my current knowledge and this may not be the best solution but it works. to use it, simply add this script to a model give the model a mass in the physics tab set its physics mode to character controller and you are done i must admit that when i saw this game engine on steam i thought that there would be more tutorials and and code snippets to use and learn from but i have found that these are somewhat rare to find at the moment and i also find while reading some posts is that there is a certain elitism going on with unhelpful replies such as "learn Lua" and the likes (sorry....rant over) I hope this helps ship-topdown-cammove.lua Quote Link to comment Share on other sites More sharing options...
beo6 Posted January 20, 2014 Share Posted January 20, 2014 (edited) Yeah I'm feeling really dumb here and I have to admit it's getting a bit frustrating... there really isn't a beginner friendly path here and as much as I want to learn I'm not sure where to look.... Since you mention a ball game. I had made a ball game like that for Leadwerks 3.0 here: http://www.leadwerks.com/werkspace/topic/6908-rolling-game-demo/ I can provide you with the LUA Scripts. Haven't tested them in LE 3.1 but i don't think very much has changed. Maybe it can give you an idea and helps. //Edit: the RollingPlayer.lua is the Script that goes on the Ball with a mass and the TopDown.lua goes on the Camera that should placed above your model. You will have to add code for the Y coordinate if you have vertical movement in your game. RollingPlayer.lua TopDown.lua Edited January 20, 2014 by beo6 1 Quote Link to comment Share on other sites More sharing options...
lildragn Posted January 20, 2014 Author Share Posted January 20, 2014 MaD2ko0l really appreciate that! Works great, not I have something I can break down and figure out. And I hear ya, I've been feeling a bit of buyers remorse on my end, but that's on me and I will keep at it. beo6 thx much, I'll check these out later today. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.