Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Turning off gravity

edited October 2017 in Codea Craft Posts: 324

Is it possible to disable gravity in the physics engine? Or set it to a weaker force?

I get nil when I try to read craft.physics.gravity (and also for paused) and trying to set it doesn't work. I've tried applying a countering force, but continually applying a force makes physics stop after a short time (which presumably shouldn't happen).


  • dave1707dave1707 Mod
    edited October 2017 Posts: 6,486

    @LoopSpace This works for me in my Craft Physics Example.

    EDIT: If I comment out the first line, I get (0.000000, -9.800000, 0.000000)

  • Posts: 324

    Hmm, the key appears to be to use scene rather than craft. Did you find that somewhere in the docs or example projects?

  • dave1707dave1707 Mod
    Posts: 6,486

    @LoopSpace Trial and error. I tried several different ways before it worked. After it worked, I don’t know why I didn’t try that first.

  • Posts: 324

    Sounds reasonable! Anyway, thanks. That fixed that issue.

    I'm still getting that physics just stops after applying a force for a period of time.

  • dave1707dave1707 Mod
    Posts: 6,486

    @LoopSpace Do you have a little example of what you’re doing that physics just stops. Also, what what do you mean by physics just stops.

  • Posts: 324

    @dave1707 I don't know any other way to describe it than saying it just stops. Everything stops moving, but no errors.

    Try this, the block should move in a circle.

    -- CraftPhysics
    function setup()
        scene = craft.scene()
        local e = scene:entity()
        e.model = craft.model.cube(vec3(1,1,1),vec3(0,0,0))
        e.material = craft.material.preset("Surfaces:Basic Bricks") = -15
        scene.physics.gravity = vec3(0,0,0)
        r = e:add(craft.rigidbody,DYNAMIC)
    function draw()
  • dave1707dave1707 Mod
    Posts: 6,486

    @LoopSpace Add this line at the end of setup.

  • Posts: 324

    @dave1707 Thanks! I'll give that a whirl.

  • RdoRdo
    edited October 2017 Posts: 17

    In a default project it can be turned off for an individual physics object by adding
    .gravityScale = 0 after youve created a physics object.
    for example

     physob = physics.body(CIRCLE,13)
    physob.gravityScale = 0

    But gravityScale doesn’t seem to work with a Craft Project, its also not in the documentation either. Kinematic bodies don’t collide with anything. And Static only collides with Dynamic bodies which brings us back to square one.

Sign In or Register to comment.