Jump to content

Driklyn

Members
  • Posts

    18
  • Joined

  • Last visited

Posts posted by Driklyn

  1. Have a player created from a pivot added to my map via the editor with these physics properties set:

     

    Physics: Character Controller
    Mass: 1.0
    Collision: Character
    

     

    And a floor underneath, a box with these physics properties set:

     

    Physics: Rigid Body
    Shape: Box
    Shape size: (Fit Shape)
    Mass: 0.0
    Collision: Scene
    

     

    When running the game, the player falls a few feet and lands on top of the floor correctly. However, once I move in any direction or rotate greater than +/- 45º or so on the y-axis, the player instantly warps into the floor, moving from a y-position of 0.273252 to 0.001953.

     

    Any ideas why?

     

    Here's my player script:

     

    function Script:Start()
       self.camera = Camera:Create()
       self.camera:SetPosition(self.entity:GetPosition())
    end
    
    function Script:Move()
       local w = window:KeyDown(Key.W) and 1 or 0
       local a = window:KeyDown(Key.A) and 1 or 0
       local s = window:KeyDown(Key.S) and 1 or 0
       local d = window:KeyDown(Key.D) and 1 or 0
    
       return Vec3(d - a, 0, w - s):Normalize()
    end
    
    function Script:Look()
       local mouse = window:GetMousePosition()
    
       local center = Vec2(context:GetWidth() / 2, context:GetHeight() / 2)
       window:SetMousePosition(center.x, center.y)
    
       return Vec3(mouse.y - center.y, mouse.x - center.x, 0)
    end
    
    function Script:UpdatePhysics()
       local move = self:Move()
       local look = self:Look()
    
       look   = look + self.camera:GetRotation()
       look.x = Math:Clamp(look.x, -85, 85)
    
       self.entity:SetInput(look.y, move.z, move.x, move.y)
    
       self.camera:SetPosition(self.entity:GetPosition())
       self.camera:SetRotation(look)
    end
    

  2. Thank you, Josh. Finally got it working! (I had nearly exactly what you wrote before creating this topic, but I placed SetGlobal before PushObject.)

     

    bool App::Start() {
       // create window, context, world...
    
       int stacksize = Interpreter::GetStackSize();
       Interpreter::PushObject(window);
       Interpreter::SetGlobal("window");
       Interpreter::PushObject(context);
       Interpreter::SetGlobal("context");
       Interpreter::PushObject(world);
       Interpreter::SetGlobal("world");
       Interpreter::SetStackSize(stacksize);
    
       // load map, etc...
    }
    

     

    Then, from any script:

     

    function Script:Start()
       System:Print(context:GetWidth())
       System:Print(context:GetHeight())
       System:Print(world.gravity) -- prints 0x00000000
    
       window:ShowMouse()
    end
    
    function Script:UpdateWorld()
       if window:KeyDown(Key.D) then
           System:Print("D down")
       end
    end
    

     

    This is awesome! And was much easier to do than expected... Only hiccup is that I couldn't seem to access any members of `world`, just its methods. I did, however, figure out you can do it this way instead:

     

    Interpreter::PushObject(&world->gravity);
    Interpreter::SetGlobal("worldGravity");
    

     

    worldGravity.y = worldGravity.y * -1
    

  3. Yes, I realize this, but I'm not creating the window/world in a script, as is occurring when you start from a Lua project. I need to be able to access the already created window/world (in CPP) via a script.

     

    I was thinking I might need to use the `Interpreter` class, but I'm not entirely sure how to.

  4. Started with a CPP project, but using Lua for scripted objects. Need to be able to access things like:

     

    window->KeyDown
    window->SetMousePosition
    world->gravity
    

     

    ...from within the scripts themselves, even though they are defined in a CPP header file (App.h).

     

    How exactly do I access them?

×
×
  • Create New...