Jump to content

Chris Vossen

Members
  • Posts

    688
  • Joined

  • Last visited

Posts posted by Chris Vossen

  1. Thanks for the tip on prefab.

     

    the fisrt would be some 360 direction input by mouse for the character or for some space ship :

     

    On Android instead of mouse it would be some full 360 Android circle pad.

     

    ***********************

    The second idea was but for later would be some RTS style unit movement :

    You click on terrain or any model level with mouse and your unit or character goes to that position.

     

    I'm just going to quickly post these 2 bits of code:

     

    Top Down Camera:

    
    

    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 camera's rotation

    self.entity:SetRotation(self.pitch,0,0)

    end

    function Script:UpdatePhysics()

     

    --Exit the function if the target entity doesn't exist

    if self.target==nil then return end

     

    --Get the target entity's 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

     

    Character movements: (on a goblin model)

     

    
    

    Script.camera = nil --Entity "camera"

    --Define animation sequences

    Script.sequence={}

    Script.sequence.walk=5

    Script.sequence.idle=6

    function Script:Start()

    self.currentyrotation = self.entity:GetRotation().y

    self.modelrotation = -90

    App.window:ShowMouse()

    end

    function Script:UpdatePhysics()

    local window = Window:GetCurrent()

    local move = (window:MouseDown(Key.LButton) and 1 or 0)

    local playerscreenpos = self.camera:Project(self.entity:GetPosition(true))

    local mousescreenpos = window:GetMousePosition()

    local vectorbetween = mousescreenpos - playerscreenpos

     

    self.currentyrotation = Math:ATan2(vectorbetween.y, vectorbetween.x) + self.modelrotation

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

    if move ~= 0 then

    self.entity.animationmanager:SetAnimationSequence(self.sequence.walk,0.04,200)

    else

    self.entity.animationmanager:SetAnimationSequence(self.sequence.idle,0.05,200)

    end

    end

     

    To understand the code basically

    Math::ATan2 finds the angle between the mouse and the player

    Camera::Project takes the character position in global space and converts it to screen space.

  2. So the proper way to do it is a call to World:Clear(), unfortunately we forgot to tag it for lua (and document it). I'm posting a bug report for this right now and hopefully the lua tag (and documentation) will be available with the next build.

  3. @Chris : thanks we have the free camera system now.

     

    For rocket launcher code,, what would you use ? a rocket we put below ground and just place after weapon when player fires ?

    For collision Axis box collision between rocket and mob ?

     

    In the editor I'd create a rocket model, set it's physics shape and collision type, attach a particle effect, and then save it as a prefab. Then in code I'd use the prefab load function:Prefab

     

    @Chris :

    When you'll have time, if you could post some lines about Mouse to manage direction of the character ?

     

    If I can find the time, maybe. What sort of mouse movement are you thinking of?

  4. The Time class contains many handy functions.

     

    I'd use Time::GetCurrent

     

    local nextoccurrence = Time:GetCurrent() + 6000 (6000 milliseconds aka 6 seconds)

     

    if Time:GetCurrent() > nextoccurrence then

     

    nextoccurrence = Time:GetCurrent() + 6000

    Do the function that you want every 6 seconds here

     

    end

  5. Thanks, it's a start.

    I notice that when attached to a camera, it makes the camera slowly but 'continuously' move (when the keys are not pressed).. I tried adding mass to the camera to stop it without success. Any ideas how it can be stabilised?

     

    Weird, I can't seem to recreate this. For me the camera just floats in mid air. If you zip a copy of your project and msg me with it I'll open it and take a look.

  6. Here is the start of a 3rd person camera. I'll write up a blog explaining the code tomorrow:

     

    http://www.leadwerks.com/werkspace/files/file/406-3rd-person-camera/

     

    For those who don't want to click download you can copy and paste this:

     

    
    

    Script.target = nil--Entity "Target"

    Script.distance = 5--float

    Script.debugphysics = false--bool

    Script.debugnavigation = false--bool

    Script.pitch = 35--float

    Script.angle = 180--float

    Script.pickradius = 0.5--float

    Script.verticaloffset = 1.8--float

    Script.smoothness = 30--int

     

    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)

     

    end

    function Script:UpdatePhysics()

     

    --Exit the function if the target entity doesn't exist

    if self.target==nil then return end

     

    local originalcamerapos = self.entity:GetPosition(true)

    local targetpos = self.target:GetPosition(true)

    local newcamerapos = self.target:GetPosition(true)

    targetpos.y = targetpos.y+self.verticaloffset

    self.entity:SetPosition(targetpos)

    self.entity:SetRotation(self.target:GetRotation(true))

    self.entity:Turn(self.pitch,self.angle,0)

    self.entity:Move(0,0,-self.distance)

     

    local targetpickmode = self.target:GetPickMode()

    self.target:SetPickMode(0) --so that the pick doesn't hit the target

    newcamerapos = self.entity:GetPosition()

    local pickinfo = PickInfo()

    if (App.world:Pick(targetpos,self.entity:GetPosition(),pickinfo,self.pickradius,true)) then

    newcamerapos = pickinfo.position

    end

    newcamerapos.x = Math:Curve(originalcamerapos.x,newcamerapos.x,self.smoothness/Time:GetSpeed())

    newcamerapos.y = Math:Curve(originalcamerapos.y,newcamerapos.y,self.smoothness/Time:GetSpeed())

    newcamerapos.z = Math:Curve(originalcamerapos.z,newcamerapos.z,self.smoothness/Time:GetSpeed())

    self.entity:SetPosition(newcamerapos)

    self.target:SetPickMode(targetpickmode)--return pick mode to original value

    end

  7. I created a new LUA Project.

    The script i've overwritten was the default one of the mini game.

    How to do when we create a new project to not overwritte the main Lua script ?

    It seems it's the same main Lua file called each time could we create a new project ?

     

    OR should we duplicate script , ressources etc ... to the new project location ?

     

    I'm a bit confused about that main script launched bu default smile.png

     

    So when you make a new project it includes all the default scripts.

     

    If you changed the script in the Darkness Awaits folder and want to use that script in your new project you can copy just copy and past it into the new project's script folder.

     

    Also this post might help:

    http://www.leadwerks.com/werkspace/topic/6081-le3-question-about-starting-a-project/

  8. Quick steps to making a new project:

     

    1. Make sure your current LE3 build is up to date (just click on the installer and click update)

     

    2. Open the project manager File->Project Manager

     

    post-5181-0-28459100-1362456980_thumb.png

     

    3. Click "New"

     

    post-5181-0-47816700-1362457003_thumb.png

     

    4. Select your project type (I chose Lua for this example), enter a project name, and click okay.

     

    post-5181-0-47291900-1362457027_thumb.png

     

    5. Select your project from the list and click okay

     

    6. Create a map, throw in a camera

     

    7. Save your map.

     

    post-5181-0-75749500-1362457055_thumb.png

     

    8. Click run.

  9. Finally exploring Leadwerks 3. I've discovered how to create a project but but when I run the map it always seems to start with the 'Darkness Waits' title and music then shows the scene I have created. I'm not in the Darkness Waits project so where do I either delete or change the title and music? I've looked through lua.start but there's nothing there about loading media.

     

    Hmm when you use the project manager to make a new project it should create a new App.Lua script that shouldn't have anything to do with Darkness Awaits.

     

    If you open up the App.Lua script it should look something like this: (except instead of "test2" it should say your project name)

    
    

    --This function will be called once when the program starts

    function App:Start()

     

    --Set the application title

    self.title="test2"

     

    --Create a window

    self.window=Window:Create(self.title)

    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

    local mapfile = System:GetProperty("map","Maps/start.map")

    if Map:Load(mapfile)==false then return false end

     

    return true

    end

    --This is our main program loop and will be called continuously until the program ends

    function App:Loop()

     

    --If window has been closed, end the program

    if self.window:Closed() or self.window:KeyDown(Key.Escape) then return false end

     

    --Update the app timing

    Time:Update()

     

    --Update the world

    self.world:Update()

     

    --Render the world

    self.world:Render()

     

    --Refresh the screen

    self.context:Sync()

     

    --Returning true tells the main program to keep looping

    return true

    end

×
×
  • Create New...