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 6031079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:07:51+00:00 2026-05-23T05:07:51+00:00

Not having any luck in the Corona forums, so I thought I’d try here.

  • 0

Not having any luck in the Corona forums, so I thought I’d try here.

I’m simply trying to create an object with a pivot joint. Seems simple but it’s just not working.

I just can’t figure out how to add bodies to the physics system if those bodies are part of an object that is created in a separate file (class). Hope someone can help – been struggling for weeks on this.

Here is my code:

main.lua:

local JointedObj = require("JointedObj")

local physics = require("physics")
physics.start()

local o = JointedObj.new()
o.x = 50
o.y = 200

local wall = display.newRect( 350, 10, 50, 300 )
physics.addBody ( wall, "static", {density=1, friction=1, bounce=.5})

local floor = display.newRect( 0, 300, 400, 10 )
physics.addBody ( floor, "static", {density=1, friction=1, bounce=.5})

--toss the object against the wall
o:toss(120, -160, o.x, o.y)

JointedObj.lua:

module(..., package.seeall)

--constructor
function new()
local obj = display.newGroup()

local red = display.newImageRect( "images/red.png", 27, 18 )
local blue = display.newImageRect( "images/blue.png", 11, 9 )
blue.x = -16

obj:insert(red)
obj:insert(blue)

function obj:toss(xForce, yForce, xPos, yPos )

    --THIS WORKS, BUT OBVIOUSLY THE OBJECT HAS NO JOINTS
    --physics.addBody( obj, "dynamic", {density=1, friction=1, bounce=0.3} )
    --obj:applyForce( xForce, yForce, xPos, yPos )


    --THIS IS WHAT I WANT TO DO. AS-IS, THE OBJECT JUST FALLS THROUGH EVERYTHING
    physics.addBody( red, {density=1, friction=1, bounce=0.3} )
    physics.addBody( blue, {density=1, friction=1, bounce=0.3} )
    myJoint = physics.newJoint( "pivot", red, blue, 0,0 )
    myJoint.isLimitEnabled = true
    myJoint:setRotationLimits( -30, 30 )
    --obj:applyForce( xForce, yForce, xPos, yPos )  --THIS THROWS A NIL ERROR IF UNCOMMENTED


end


return obj;
end
  • 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-23T05:07:52+00:00Added an answer on May 23, 2026 at 5:07 am

    Physics don’t work between groups, only within a group. That’s done on purpose to allow for moving cameras done using groups. Refer to the Egg Breaker demo to see what I mean. The entire scene is in a group that moves around, but objects within the group don’t react to the group moving.

    Incidentally, the reason that last line throws an error is because you can only use applyForce on a physics body and you haven’t set a physics body on “obj”, only on “red” and “blue”.

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

Sidebar

Related Questions

I'm trying to databind my repeater but so far not having any luck. Anyone
I'm trying to do something I thought was simple, but I'm not having any
I am trying to run this in Chrome/Firefox Console but not having any luck.
I'm trying to programmatically start explorer.exe but I'm not having any luck. This is
I am trying to get compass/sass/haml working using blueprint but not having any luck
I'm trying to edit login.php for sqlbuddy and not having any luck. I want
Trying this answer and not having any luck: I am using the SQLite Database
I'm interfacing with a payment gateway and not having any luck with Net::SSLeay and
Taking Sql this quarter and not having any luck with the following question: The
I am using Webtechnick's Facebook Plugin - but I am not having any luck

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.