Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6657583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:47:09+00:00 2026-05-26T01:47:09+00:00

I am using the lua love engine to make a simple game. However, im

  • 0

I am using the lua love engine to make a simple game. However, im having a little trouble with collision.

I have a polyline between a set of points (representing the rocky ground) and a box I need to collide with it, but I cant think of an easy implementation.

love.graphics.line( 0,60, 100,70, 150,300, 200,230, 250,230, 300,280, 350,220, 400,220, 420,150, 440,140, 480,340 )

If anyone could help with code snippets or advice, it would be much appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T01:47:11+00:00Added an answer on May 26, 2026 at 1:47 am

    You need to create a more abstract representation of the ground, from which you can generate both the line for the graphics, and the body for the physics.

    So for example:

    --ground represented as a set of points
    local ground = {0,60, 100,70, 150,300, 200,230, 250,230, 300,280, 350,220, 400,220, 420,150, 440,140, 480,340}
    

    This may not be the best representation, but I will continue with my example.

    You now have a representation of the ground, now you a way of converting that something that your physics can understand (to do the collision) and something that your graphical display can understand (do draw the ground). So you declare two functions:

    --converts a table representing the ground into something that
    --can be understood by your physics.
    --If you are using love.physics then this would create 
    --a Body with a set PolygonShapes attached to it.
    local function createGroundBody(ground)
        --you may need to pass some additional arguments,
        --such as the World in which you want to create the ground.
    end
    
    --converts a table representing the ground into something
    --that you are able to draw.
    local function createGroundGraphic(ground)
        --ground is already represented in a way that love.graphics.line can handle
        --so just pass it through.
        return ground
    end
    

    Now, putting it all together:

    local groundGraphic = nil
    local groundPhysics = nil
    love.load()
        groundGraphic = createGroundGraphic(ground)
        physics = makePhysicsWorld()
        groundPhysics = createGroundBody(ground)
    
    end
    
    love.draw()
        --Draws groundGraphic, could be implemented as
        --love.graphics.line(groundGraphic)
        --for example.
        draw(groundGraphic)
        --you also need do draw the box and everything else here.
    end
    
    love.update(dt)
        --where `box` is the box you have to collide with the ground.
        runPhysics(dt, groundPhysics, box)
        --now you need to update the representation of your box graphic
        --to match up with the new position of the box.
        --This could be done implicitly by using the representation for physics
        --when doing the drawing of the box.
    end
    

    Without knowing exactly how you want to implement the physics and the drawing, it is hard to give more detail than this. I hope that you use this as an example of how this code could be structured. The code that I have presented is only a very approximate structure, so it will not come close to actually working. Please ask about anything that I have been unclear about!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble using one Lua lib from inside another. I'm not sure about
I'm making an iPhone game in .lua using IntelliJ IDEA, and I have a
I am working on a game engine in C++ using Lua to define NPCs.
I'm working with Lua and C++ (using LuaWrapper) and I'm having trouble with something.
I'm working on a game engine in C++ using Lua for NPC behaviour. I
I'm working with large numbers that I can't have rounded off. Using Lua's standard
OK so I have a C++ class that is exposed to Lua using SWIG.
How do I extract files using Lua? Update: I now have the following code
I have an executable I want to run using Lua ... how do I
I have the following lua script : module(modoo,package.seeall) foo=1 bar={12,34} Which works fine using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.