Jump to content

Chris Vossen

Members
  • Posts

    688
  • Joined

  • Last visited

Posts posted by Chris Vossen

  1. I created a slimmed down version of a camera script, it doesn't do any fancy raycasting but I feel is fairly readable.

     

    Script.target = nil--Entity "Target"
    Script.distance = 10--float
    Script.debugphysics = false--bool
    Script.debugnavigation = false--bool
    Script.pitch = 20--float
    Script.height = 10--float
    function Script:Start()
    if self.target==nil then return end
    
    --debug functions for viewing physics or navigation in game
    self.entity:SetDebugPhysicsMode(self.debugphysics)
    self.entity:SetDebugNavigationMode(self.debugnavigation)
    
    --Set the cameras rotation
    self.entity:SetRotation(self.pitch,0,0)
    end
    function Script:UpdatePhysics()
    
    --Exit the function if the target entity does not exist
    if self.target==nil then return end
    
    --Get the target entitys position, in global coordinates
    local p0 = self.target:GetPosition(true)
    --Calculate the new camera offset
    local offset = Vec3(p0.x,p0.y+self.height,p0.z-self.distance)
    
    --Add our original offset vector to the target entity position
    p0 = offset
    self.entity:SetPosition(p0,true)
    
    end
    

  2. Ok so this is the code, this script i attatch to an object and drag the camera entity into the target.

     

    Script.target = nil--Entity "camera"
    
    local tposition = Vec3()
    
    function Script:Start()
    tposition = self.target:GetPosition()
    tposition = Vec3(tposition.x,tposition.y,tposition.z)
    self.entity:SetParent(self.target)
    end

     

    The object dissapears, ive tried offseting it from the camera but no show. If i set the target to another object in the editor it works fine.

     

    Andy

     

    So I tested out your script by attaching it to a box in Darkness Awaits, I then put the camera in the entity field.

     

    When I ran the game the box seemed to move how you would expect it to when parented to the camera.

     

    post-5181-0-17693800-1362438689_thumb.png

     

    If I had to take a random guess I'd say that the object that you are setting as a child of the camera is being moved off screen or behind the camera.

     

    I'd check their positions real quick (throw this in after the call to set parent and then check the Output box after running the game:

     

    System:Print("camera / tposition: " .. tposition:ToString().."  object position: "..self.entity:GetPosition():ToString())
    

  3. Okay so there are a handful of ways to access an entities information from Lua scripts.

     

    1. If the script is attached to the entity you want to access.

     

    In this case you just call self.entity and it refers to the entity that the script is attached to.

     

    For example, in the player script (which is attached to the barbarian model) there is a call:

     

    
    self.entity:SetInput(self.currentyrotation,move,0,0,false,self.maxAcceleration)
    

     

    This part confused me when I first started Lua scripting: self.entity refers to the entity that it is attached to, which is the barbarian model. So in my mind it's like calling "Model:SetInput(...)"

     

    If you had a script attached to a camera and you wanted to call a camera specific function "Set Range" the function call would be:

     

    self.entity:SetRange(range.x,range.y)
    

     

    this is because the entity that the script is attached to is a camera so the call is essentially camera:SetRange(...)

     

    2. If the entity is declared in another Lua Script (And was not declared as local)

     

    In App.lua context is created as

    self.context=Context:Create(self.window,0)
    

     

    to access this from another script you could call

    App.context:GetWidth()
    

     

    3. You want access to an entity that is in the editor and the script is not attached to.

     

    The simplest way to do this is to declare an entity variable in your script and then select it in the editor.

     

    For example in the camera class at the near the top of the script there is a variable "target" and it is declared as

     

    Script.target = nil --Entity "Target"
    

     

    By using "--Entity" tag after declaring the variable the editor will now have an entity field in the script tab.

    post-5181-0-65154400-1362350327_thumb.png

     

    You finally can drag and drop an entity from the scene tab to the entity field

    post-5181-0-78708100-1362350365_thumb.png

     

    4. Various other ways

     

    World::ForEachEntityInAABBDo

    World::ForEachVisibleEntityDo

     

    For the specific example of a camera, I would go with option 2 and declare it in app.lua.

     

    self.camera = Camera:Create()
    

     

    then access it from other scripts as

     

    App.camera
    

    • Upvote 1
  4. Try setting the nav obstacle parameter to true, it's the bottom most check mark on the physics tab

     

    post-5181-0-65220000-1362271078_thumb.png

     

    One helpful setting that you can use if you are working with the navigation system, is to turn on the show navigation in the editor. View->Show Navigation

     

    post-5181-0-13734900-1362271242_thumb.png

     

    hopefully this helps

  5. A couple of Android queries:

     

    1) Will it be possible to change the build target from the default to 4.x.x Jellybean for instance?

     

    2) Will it be possible to incorporate the Google licensing api if required?

     

    3) If needs be am I free to modify the android manifest?

     

    Thanks.

     

    I'm going to have to deffer these to Josh.

  6. Awesome handfull new shader smile.png

     

     

    I have some problem to understand that bit of code :

     

    function EnemyForEachEntityInAABBDoCallback(entity,extra)

    if extra.goblinai.target==nil then

    if extra~=entity then

    if entity.player~=nil then

    extra.goblinai.target=entity.player

    end

    end

    end

    end

     

    What is goblinai ? the name of script file ?

    target is the global variable in this script instance ?

     

    Why having all that tests why not directly do :

    extra.goblinai.target=entity.player

    caus extra will always be an entity passed throught the function ?

     

    Quick Answer: goblinai is the name of the script attached to the goblin entity. The declaration of target was actually a slip up on my part, it should have been declared at the top of the script as Script.target = nil.

     

    This brings up a good point on how flexible Lua is (which can get you into trouble sometimes) since self.target is not declared anywhere, when something is assigned to it lua creates the variable on the fly. It will not be global because of the prefix "self".

     

    Long Answer:

     

    To fully understand this code you have to look at these two chunks of code:

     

    --Check for a new target in the area
    if not self.target then
    if time-self.lastCheckForTargetTime>500 then
    self.lastCheckForTargetTime=time
    local position = self.entity:GetPosition(true)
    local aabb = AABB()
    
    aabb.min.x=position.x-self.sightRadius
    aabb.min.y=position.y-self.sightRadius
    aabb.min.z=position.z-self.sightRadius
    aabb.max.x=position.x+self.sightRadius
    aabb.max.y=position.y+self.sightRadius
    aabb.max.z=position.z+self.sightRadius
    aabb:Update()
    self.entity.world:ForEachEntityInAABBDo(aabb,"EnemyForEachEntityInAABBDoCallback",self.entity)
    
    if self.target then
    self.entity:EmitSound(self.sound.attack[math.random(0,#self.sound.attack)])
    self.currentState=self.state.chase
    self.entity:Follow(self.target.entity,self.speed,self.maxaccel)
    --self.entity:SetMass(self.mass)
    self.followingTarget=true
    end
    end
    end
    

     

    and

     

    function EnemyForEachEntityInAABBDoCallback(entity,extra)
    if extra.goblinai.target==nil then
    if extra~=entity then
    if entity.player~=nil then
    extra.goblinai.target=entity.player
    end
    end
    end
    end
    

     

    Basically if the goblin does not have a target assigned an AABB (axis aligned bounding box) is created around the goblin with a height, width, and depth of the goblins sight radius.

     

    self.entity.world:ForEachEntityInAABBDo(aabb,"EnemyForEachEntityInAABBDoCallback",self.entity)
    

     

    The foreachentityinaabbdo function is then called on the newly created aabb. The call back function name "EnemyForEachEntityInAABBDoCallback" is passed in as parameter 2, this means that for every entity within the aabb the callback function "EnemyForEachEntityInAABBDoCallback" will be called. Finally parameter 3 is self.entity which in this case refers to the specific goblin model that the script is attached to.

     

    Now the function "EnemyForEachEntityInAABBDoCallback(entity,extra)"

    extra is the extra passed in from earlier (the goblin model) and entity an entity that that is within the aabb.

     

    if extra.goblinai.target==nil then
    

    extra is the passed parameter, which was self.entity (the goblin model), goblinai is the specific script attached to the goblin model and target is the variable (which was sloppily created on the fly, my bad).

     

     if extra~=entity then
    

    You are trying to only find entites with a player script attached. So you begin by making sure that the entity in this call is not the goblin who the aabb is around.

     

      if entity.player~=nil then
       extra.goblinai.target=entity.player
      end
    

     

    finally if the entity found is not the goblin and has a player script attached (entity.player~= nil) then the goblin's target is the new entity that is found.

     

     

    extra.goblinai.target=entity.player

     

    would not work because the entity that is passed in is not guaranteed to have a player script attached.

     

    Wow this was a long winded answer, hopefully it helps a little. I can gladly explain / clarify any specific sections of code.

  7. Hi, I'm getting the following error in lua; 'attempt to index global 'Map' (a nil value). sad.png

     

    function App:Start()
    
    --Set the application title
    self.title="MyGame"
    
    --Create a window
    self.window=Window:Create(self.title,0,0,1024,768,Window.Titlebar+Window.Center+8)
    --self.window:HideMouse()
    
    --Create the graphics context
    self.context=Context:Create(self.window,0)
    if self.context==nil then return false end
    
    --Create a world
    self.world=World:Create()
    
    --Load a map
    return Map:Load("Maps\start.map")
    end
    

     

    Try: adding in an extra backslash

    return Map:Load("Maps\\start.map")
    

  8. If you're ever wondering what a function does, every function should have a complete example program in both C++ and Lua.

     

    This means you can copy and paste an entire Lua example into App.Lua (Make sure you save a copy of the original somewhere, or you can always delete it and click update on the installer) and click run!

     

    Wondering what GoToPoint does? Throw the Lua example in as App.Lua and viola.

     

    post-5181-0-50150900-1362185771_thumb.png

    • Upvote 2
  9. Models in Leadwerks 3 are basically the same as a Mesh in Leadwerks 2. A model can have one or more surfaces. In this case, the material you are looking for is applied to the model surface, so it will be something like this:

    local child = self.target:GetChild(1)
    local surface = child:GetSurface(0)
    local material = surface:GetMaterial()

     

    Since GetChild() returns an entity, and GetSurface() is a Model class command, you might need to cast the entity object to a model:

    http://www.leadwerks...ng-with-lua-r57

     

    Note that all indexes in Leadwerks 3 begin with 0, so 0 is the first entity or surface, 1 is the second, etc.

     

    The lua example in Model::GetSurface might help as well.

  10. However, why would the goblin not follow the hero when he stepped back on the path? You see me walking around the goblin below him and he completely ignores the character.

     

    Also, what causes that pinball bounce off of the wedges and how would that be resolved? In my mind, wedges should either act like ramps or walls (neither should bounce the player) but perhaps there's more to this.

     

    The goblin not following again might possibly be an issue with my goblin AI (I'll have to look into this a little bit later)

     

    There is an entity command that needs to be exposed to determine MaxSlope for entities. If the slope is too steep the player will slide down else it will act as a ramp. If you just wanted the visuals of a ramp and the collisions of a "wall" you could set the physics shape to a box.

     

    I'll add exposing the command and investigating the following issue onto my todo list (It's a little long at the moment)

  11. Hi Chris, when executing a project in either debug or release mode a console window opens up before the main application window listing all the assets being loaded etc. Is there a way to suppress the console on a release build?

     

    Okay I haven't tested this but I believe there are currently 2 steps to accomplish this:

     

    1. Make sure you can compile for visual studios

     

    Compiling with Visual Studio

     

     

    2. Change the linker subsystem property to Windows

     

    Project->Properties->Linker->System->SubSystem

     

    post-5181-0-07823100-1362180180_thumb.png

  12. I can see no animate command in Leadwerks 3.

    How would I animate a character with a walk sequence containing a framebegin value of 1 and a frameend of 40?

     

    The most convenient way of animating a model in lua is to attach the "AnimationManager" script (located at \Scripts\Animation\AnimationManager.lua) then call "SetAnimationSequence"

     

    an example of this is in the Player.lua class (which is attached to the barbarian in Darkness awaits) Lines 219 through 235.

     

     

    If you don't want to use the animation manager you could call the entity SetAnimationFrame command. Animation commands are grouped together in Entity

  13. Question: "Why can't I create new primitives directly in the main viewport? I would prefer to drag-n-drop them from the toolbar (giving me e.g. a unit cube) and then resize/reposition them using their property window (or the mouse)."

     

    Answer:

    If you would prefer to drag and drop a unit cube you could:

     

    1. In 2d viewports create a 1x1x1 using the primitive box

     

    post-5181-0-23209800-1362178507_thumb.png

     

    2. Right click on your box in the scene tab and select "Save as Prefab"

     

    post-5181-0-57125700-1362178563_thumb.png

     

    3. Name it and save it

     

    4. Select your prefab from the asset browser and drag n drop into the main viewport:

     

    post-5181-0-53420400-1362178618_thumb.png

  14. Thanks. But that doesn't change the numbers in the graph but rather multiplies them, right? I find that confusing since I can't easily compare the sizes. The scale makes sense for imported models, but when I create a cube I want to directly enter its size.

     

    In the editor: You can select the object in the main viewport and their dimensions will appear in the 2d viewports where you can see their dimensions and resize accordingly.

     

    or

     

    If you are working in code: Box

     

    post-5181-0-91443400-1362178074_thumb.png

  15. Question: "Are there any commands/shortcuts to snap to the grid? Or to align objects? Without that it's pretty hard to construct the scene you want."

     

    Answer: You can adjust the grid size via View->Increase Grid Size or View->Decrease Grid Size "short cut key are the brackets '[' and ']' " When you create primitives they will automatically be created according to the grid size.

  16. Question: "I create a new project using the Project Manager (Lua). I would have expected that I can run the project right away, but it doesn't seem to work. Opening App.lua in the Script Editor and hitting F5/F6 just notifies me that <myproect>.debug.exe couldn't be launched."

     

    Answer: Josh is on this right now. I'll post more when he's done.

  17. Question: "Isn't there a way to change the size of models by entering their numbers? The viewports show me the sizes, but I seem only to be able to change them using the mouse which is awkward."

     

    Yes.

     

    - Select your model by clicking on the scene tab

    - Now there is a tab that says general and within it there are parameters for scale

     

    post-5181-0-82858200-1362176626_thumb.png

     

    If you want to scale the model as a whole you can use the model editor:

     

    post-5181-0-78927200-1362177289_thumb.png

×
×
  • Create New...