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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:08:23+00:00 2026-06-12T12:08:23+00:00

I want to make a moon rotating around a planet, or something along that

  • 0

I want to make a moon rotating around a planet, or something along that analogy. So is there something I can call for physics.setGravity(0,0) that changes the position that the gravity pulls towards, particularly assigning that to be a physics body? If not, simply a specific x-y coordinate will be fine.

local moon = display.newImage ("moon.png")
physics.addBody(moon, {bounce=0, density=1.0})
local earth = display.newImage ("earth.png")
physics.addBody(earth, {bounce=0, density=1.0})

Thanks

  • 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-12T12:08:24+00:00Added an answer on June 12, 2026 at 12:08 pm

    Instead of playing around with the setGravity option, I think you should just rotate the images using something like this:

    local physics = require("physics")
    physics.start()
    physics.setGravity(0, 0)
    display.setStatusBar( display.HiddenStatusBar )
    
    local background = display.newImage( "space.png", true )
    background.x = display.contentWidth / 2
    background.y = display.contentHeight / 2
    
    local earth = display.newImage( "earth.png" )
    earth.x = 100; earth.y = 200
    earth.xScale = 0.7
    earth.yScale = 0.7
    physics.addBody( earth, {radius=40 } )
    earth.bodyType = "static"
    
    local moon = display.newImage( "moon.png", 40, 40)
    moon.x = earth.x + 80
    moon.y = earth.y
    moon.xScale = 0.3
    moon.yScale = 0.3
    moon.rotation = 100  
    physics.addBody( moon, {radius=10 } )
    moon.bodyType = "dynamic"
    
    myJoint = physics.newJoint( "pivot", moon, earth, earth.x, earth.y )
    
    local orbit = function( event )    
            moon.rotation = moon.rotation + 1.5
    end
    

    Notice that I am not really mucking about with setGravity, but the speed of the rotation is defined in the orbit function.

    The above code assumes you just have image files to represent your planetary bodies. If so, you will have to play around with the constants above (earth.x and earth.y, scaling values, etc) to make the whole system LOOK right for the images you choose.

    Good luck!

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

Sidebar

Related Questions

I want make interactive application where user launches it and can do various task
I want make the control height as double when the mouse is over that
I want make a simple referral system. Basically referral URL structure something like this.
I want make a xslt transformation to xsl-fo but I´m not really sure that
i want make function like that function(data){ } i want this data as this
I want make a page (HTML + CSS) that fits all the space left
I want make something like animation. I have four UIImageView (names: IW1, IW2, IW3,
I want make a UI that is semi transparent in WPF VS2008, so I
I want make pretty URL (contact.php?id=something to contact/something) with this code in .htaccess, but
I want make some quizes about movie. There is quiz mutable array with 10

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.