Jump to content

aldoz

Members
  • Posts

    31
  • Joined

  • Last visited

Posts posted by aldoz

  1. There is some way to translate the MonsterAI.lua to get it's working with full physics too?

     

    I notice the navigation, in these scripts, are made for flat surfaces; you notice that monsters are not handled by physics;

    Maybe I want too much :)

  2. In first, thank you to all you guys for fast answers!

     

    Does it have a mass on the physics tab > 0?

     

    I tried using no mass and mass >0 but nothing changes :\

     

    Hi aldoz,

     

    Maybe you give us some more information, maybe part of the code or something. My tip is you start creating your own AI, search the web, gather information needed from the API Reference. Why? Well thats the best way learing how to fix problems on your own and to understand unfamiliar code and the community is still here to help you if you need it.

     

    Now lets come to your problem. In Leadwerks it is very easy to make an entity follow your player or go to a point.

     

    You can read more about this features here:

     

    Follow: http://www.leadwerks.com/werkspace/page/api-reference/_/entity/entityfollow-r697

    Go To Point: http://www.leadwerks.com/werkspace/page/api-reference/_/entity/entitygotopoint-r700

     

    This functions uses navigation mesh, so dont forget to build a NavMesh for your map!! I guess that may be your fault? Because if you use the original MonsterAI.lua there isn't much you can do wrong.

     

    Damn.. I think there is something I am missing.. I will read your links, I need to understand some logics about AI scripts and abut general lua programming

     

    Did you build the nav mesh?

    mmm interesting.. . No! I am not using nav mesh! So I suppose I need to incorporate my enemy object inside a nav mesh.. right?

    Can you provide me some sort of examples?

  3. Hi guys,

    I am trying to get an entity that move in direction of the player!

     

    I am using MonsterAI.lua but I notice that the object where I activate MonsterAI.lua can't move! even I provide a target to follow.

     

    Some of you have a solution?

  4. This is a common thing people ask about. To directly link an entity into your script you could do it by adding the following line of code to the top of your ball script.

     

    Script.cube = nil --Entity "Cube"
    

     

    With this code you can go into the editor and select your ball entity, then go to the script tab, there should now be a box labeled "Cube", drag the cube from the Scene tab into this box. Now within your script you could do something like

    local distance = self.entity:GetDistance(self.cube)
    

     

    There are many other ways to do this and without knowing more about what you are trying to accomplish, another method might be better.

     

    Thank you so mutch mate!, finally it's working fine! smile.png

    I was getting mad about!

    Thanx to nick.ace too!

  5. I think we need to see a little more of the project. It sounds like you are making an object in the editor and expecting it to be available in a local script. The scope of cube is outside of the ball script.

     

    Yeah exactly!

     

    I was trying to use script proprierties;

    Inside the ball script I add this command : Script.myEntity = entity --entity "Some entity"

     

    So I get the textfield called "Some entity" where I could put an object to let this object is available in ball script but.... I can't choose nothing in that texfield! Seems to be disabled... (remember I am using Leadwerks demo)

     

    So can I make a script on the cube where I set the cube proprierties as global.. cool.. but how I can do it?

  6. I try to explain better.

     

    I use interface to make a new object, a ball.

    Then I make a new object, a cube,

     

    Now I go to object ball script and I use the following code to calculate the distance to the cube:

     

    pos1 = self.entity:GetPosition()
    pos2 = cube:GetPosition()
    

     

    but pos2 get me a nil error.. like "cube" is not know by the ball script!

     

    So you can see I need to call the object cube from the ball script but in this script there is NOT the creation of the cube object! (the object cube is born from Leadwerks interface, not by script code!)

     

    I am a bit confused about..

    :\

  7. Syntax is wrong. should be:

    distance = entity1:GetDistance(entity2)

     

    http://www.leadwerks.com/werkspace/page/api-reference/_/entity/entitygetdistance-r800

     

    Hi macklebee, sorry for my insistence;

    considering entity1 name is FPSPlayer under Entity scene folder and..

    considering entity 2 name is SPHERE under Models scene folder..

     

    so, in your code how I need to name these objects (entity1 and entity2)?

     

    and I need to set global variable distance?

  8. As in the title, I am trying to calcolate the distance between an object (sphere) in my scene and my FPSPlayer.

    I am using this code as script of sphere object :

     

    distance = GetDistance(Entity*FPSPlayer)

     

    It's basic, I know... but I get all time same error : Script Error Attempt to perform operation on an invalid operand...

     

    Help!

     

    I tried this code I find in steam forum but in this case too I can't use the right syntax when I must change "obj1" and "obj2" with the LUA command..:

     

    pos1 = GetPosition(Obj1)
    pos2 = GetPosition(Obj2)
    distance = length(pos2 - pos1)
    

  9. Ok, I tried many things and finally I solve this trouble.

     

    Just the terrain example born with some strange collision behaviour or maybe just me editing and changing too much the terrain example..

     

    So I restart my project using the ball game example and I notice that the collision behaviour follow the previous mentioned collision rules :

    http://www.leadwerks.com/werkspace/page/api-reference/_/command-reference/collision-r778

     

    So now If use the stones as debris and the wall as character I get my stones pass through wall but the player not.

    So solved smile.png

    Thank you guys

  10. Ok I am trying to set your collision code for single objects; so I selected a single stone object and I put this code in his script page:

     

    Collision.Custom = 10
    Collision:SetResponse(Collision.Custom,Collision.Custom,Collision.Collide)
    Collision:SetResponse(Collision.Custom,Collision.Scene,Collision.Collide)
    self.entity:SetCollisionType(Collision.Custom)
    

     

    But I get : Script Error attempt to index global 'self' (a nil value)..

    I think I not yet catch the right logic behind Leadwerks..

  11. Damn I can't get working your code...

     

    I am inside in a custom "terrain example" project.

    Take the terrain example, add a wall in front of player and a little box (as stone) on the groud and you know my situation.

     

    I try to put your code in a blank project using the script editor but I get just a black screen..

    anyway I suppose that I could to use some pieces of your code directly as script for the wall and the stones...

     

    Collisions start to be hard to handle for me :\

     

     

    EDIT : ok I run your example adding your code in the player script.. (lol)..

    So I get 2 windows, one is the game and one is your example.. and yes I see you got the point!

     

    Now I hope to find some way to add to my code..

  12. Hi again guys,

     

    I am trying to get this situation :

     

    You use a player on a terrain; in front of player there is a wall.

    Near the player there are some little stones ready to be throw to the wall!.

     

    Ok what I would is to obtain the player CAN'T go through the wall but the stones yes!

     

    Obviously if I turn off collision for the stones so I will get my stones sink inside the terrain. So I need something to choose for each of the objects , which are the other objects with which to have a collision..

    In other words :

    Stone 1 ------> Can collide with Stone2 and Stone3 - Can't collide with Wall

    Stone 2 ------> Can collide with Stone 1 - Can't collide with Stone3 and Wall

     

    Can I obtain something like that?

  13. Ok with the following code I can put a text on the center of the screen!

    So, solved smile.png

     

    function Script:Start()
    self.font = Font:Load("Fonts/Ranchers-Regular.ttf",32)
    if self.font==nil then
    local context = Context:GetCurrent()
    self.font = context:GetFont()
    end
    end
    
    function Script:PostRender(context)
    context:SetBlendMode(Blend.Alpha)
    context:SetColor(1,0,0,1)
    local text
    local prevfont = context:GetFont()
    prevfont:AddRef()
    context:SetFont(self.font)
    local fh=self.font:GetHeight()
    local timestring
    
    text="Level Complete"
    context:DrawText(text,(context:GetWidth()-self.font:GetTextWidth(text))/2,(context:GetHeight()-fh)/2-fh*1.5)
    end
    

    • Upvote 2
  14. Ok I get this working :

     

    function App:Start()
    
        self.window = Window:Create()
        self.context = Context:Create(self.window)
        local font = Font:Load("Fonts/Arial.ttf",36)
        self.context:SetFont(font)
        font:Release()
        return true
    end
    function App:Loop()
        if (self.window:Closed() or self.window:KeyDown(Key.Escape)) then return false end
    
        self.context:SetColor(0,0,0)
        self.context:Clear()
    
        --Draw some centered text on the screen
        local text = "Leadwerks"
    
        local font = self.context:GetFont()
        local x = self.window:GetWidth()/2
        local y = self.window:GetHeight()/2
        x = x - font:GetTextWidth(text)/2
        y = y - font:GetHeight()/2
        self.context:SetBlendMode(Blend.Alpha)
        self.context:SetColor(1,1,1)
        self.context:DrawText(text,x,y)
        self.context:SetBlendMode(Blend.Solid)
        self.context:Sync()
        return true
    end
    

     

    Using this code inside the ball script, when I push esc key so I read the write!

    • Upvote 1
  15. mmm tried but nothing change.

     

    I notice that, when I get out from demo, using esc key, I get "Script Error attempt to index field 'window' (a nil value)

     

    If I delete the first script line so I get this error in the following code line : Script Error attempt to index field 'context' (a nil value)

     

    Damn me when I lost time using Dark Basic :)

  16. Hi again guys, I am trying to put some text on my screen but a basic thing such this seems impossible for me... I can't get text and the only thing I get is NO texts on screen.

    Tried a bunch of forum examples but nothing!

     

     

    So, I put a sphere on the "terrain demo" and I made a script to let to push it pressing a key.

    This work fine!

     

    But in the same script I add a function to draw some text using App:loop but I am not sure.... I getting nill value error too..

     

    here my code :

     

    function Script:UpdatePhysics()
    
      if window:KeyDown(Key.F) then  
        self.entity:AddForce(50,0,0,true)
      end
    
    end
    
    
    
    
    function App:Loop()
        if (self.window:Closed() or self.window:KeyDown(Key.Escape)) then return false end
    
        self.context:SetColor(0,0,0)
        self.context:Clear()
    
        --Draw some centered text on the screen
        local text = "Leadwerks"
    
        local font = self.context:GetFont()
        local x = self.window:GetWidth()/2
        local y = self.window:GetHeight()/2
        x = x - font:GetTextWidth(text)/2
        y = y - font:GetHeight()/2
        self.context:SetBlendMode(Blend.Alpha)
        self.context:SetColor(1,1,1)
        self.context:DrawText(text,x,y)
        self.context:SetBlendMode(Blend.Solid)
        self.context:Sync()
        return true
    end
    

  17. Hi all, I am searching for set position and set rotation commands.. but nothing?

    And over that, are there some command to push a physical object with some physical force?

     

    something like "add force vector XYZ"

     

    Thank you in advance

×
×
  • Create New...