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

  • SEARCH
  • Home
  • 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 7802971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:25:17+00:00 2026-06-02T01:25:17+00:00

i have some trouble with the custom shapes in corona. Here is my code

  • 0

i have some trouble with the custom shapes in corona.

Here is my code and what it does is that i’m adding some spheres to the scene so that they fall inside a basket, this basket is the custom shape object that i defined in the newBasket() function, the problem is that the basket does collide with the ground object but it doesn’t collide with the spheres and i don’t know why, please someone help me here, i can’t find a solution elsewhere, thanks in advance.

_W = display.contentWidth
_H = display.contentHeight

--Physics
local physics = require("physics")
physics.start()
physics.setDrawMode("debug")

-- iOS
display.setStatusBar(display.HiddenStatusBar)

-- screen boundaries
local ground = display.newRect(0, _H, _W, 5)
local leftWall = display.newRect(0,0,1,_H)
local rightWall = display.newRect(_W,0,1,_H)
physics.addBody(ground, "static", {friction = .2, bounce = .1})
physics.addBody(leftWall, "static", {friction = .2, bounce = .1})
physics.addBody(rightWall, "static", {friction = .2, bounce = .1})

local function newBasket()
    local body = display.newImage("assets/basket.png")
    body.x = 0 body.y = 0

    local physics_body = {}
    physics_body["basket"] = {
        {
            --LeftArm
            density = 10, friction = 10, bounce = 0.15, 
            shape = {-126, 40, -110, 40, -140, -64, -156, -64}

        },

        {
            --Bottom
            density = 10, friction = 1, bounce = 0, 
            shape = {-121, 60, 125, 60, 128, 40, -126, 40}

        },
        {
            --RightArm
            density = 10, friction = 10, bounce = 0.15, 
            shape = {113, 40, 129, 40, 158, -64, 143, -64}

        }

    }
    physics.addBody(body, unpack(physics_body["basket"]) )

    return body
end

local basket = newBasket()
basket.x = _W * .5 basket.y = _H - 100

local function newPlanet()

    local planets = {
        {img = "bigBall.png", radius = 45},
        {img = "mediumBall.png", radius = 30}, 
        {img = "smallBall.png", radius = 20}
    }

    local n = math.random(1,3)

    local img = "assets/" .. planets[n].img
    local ball = display.newImage(img)
    ball.x = math.random((_W * 0.5) -100, (_W * 0.5) + 100) ball.y = 0

    physics.addBody(ball, {bounce = 0.3, radius = planets[n].radius})
end

local function spawnPlanets(number)

    local function spawn(e)
        newPlanet()

        if(e.count == number) then
            timer.cancel(tmr)
            tmr = nil
        end
    end

    tmr = timer.performWithDelay(500, spawn, number)
end

spawnPlanets(20)
  • 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-06-02T01:25:18+00:00Added an answer on June 2, 2026 at 1:25 am

    According to the manual:

    If a shape is specified, then the body boundaries will follow the polygon provided by the shape. Note that the maximum number of sides per shape is eight, and all angles must be convex. […] The shape coordinates must be defined in clockwise order, and the resulting shape must be convex-only.

    So you have two issues working against you. First the shapes must be defined in clockwise order, as I’ve done in the below example. Secondly, all shapes must be convex (even complex body shapes) so you can’t do anything that turns in on itself like a crescent moon or basket.

    Unfortunantly, this means you have to make your basket as 3 separate shapes. Also, since they are now separate shapes, they won’t stay stuck together when they fall (unless you use joints). I’ve just made the basket 3 static bodies and put it in the right place to start with:

    local function newBasket()
        local physics_body = {}
        physics_body["basket"] = {
            {
                --LeftArm
                density = 10, friction = 10, bounce = 0.15,
                shape = {-126, 40, -156, -64, -140, -64, -110, 40 }
    
            },
    
            {
                --Bottom
                density = 10, friction = 1, bounce = 0,
                shape = {-121, 60,-126, 40, 128, 40, 125, 60 }
    
            },
            {
                --RightArm
                density = 10, friction = 10, bounce = 0.15,
                shape = {113, 40, 143, -64, 158, -64, 129, 40 }
    
            }
    
        }
        for k,shape in pairs(physics_body["basket"]) do
            local body = display.newRect(0, 0, 200, 100)
            body.x = display.contentCenterX
            body.y = display.contentHeight - 60
    
            physics.addBody(body, 'static', shape )
        end
    end
    
    newBasket()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm have some trouble with the fulltext CONTAINS operator. Here's a quick script to
I'm having trouble getting a custom config section to work. It's some code I
I have some trouble when using SPUtility.SendEmail method in a custom workflow. private void
I am have some trouble specifying a custom icon in my WPF applicaion. I
I have been having some trouble lately with using custom classes as types. As
I have upgraded some VB6 code, which uses fixed length strings in custom types,
I have some trouble with my trac installation (version 11.4). What should I do
I have some trouble with jquery ui-events: In my application, there are some sliders.
I have some trouble achieving adequate real-time performance from my application and wondering if
I am mlearning javascript and have some trouble creating an onject via prototype. I

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.