Jump to content

Moving a character that's not FPS


lildragn
 Share

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

  1. Make a new lua script.
     
  2. 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)
     
  3. Try moving parts of the code from the script above, in to the Start and Update() function of your new script.
     
  4. If you get stuck there, post your script in a new topic and ask for help.
     
  5. This way you learn about object scripts and you will learn bit by bit how to do stuff in Lua.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 by beo6
  • Upvote 1
Link to comment
Share on other sites

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.

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