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 23 in Codea Craft Posts: 299

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).

Comments

  • dave1707dave1707 Mod
    edited October 23 Posts: 6,325

    @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)

        scene.physics.gravity=vec3(0,0,0)
        a=scene.physics.gravity
        print(a)
    
  • Posts: 299

    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,325

    @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: 299

    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,325

    @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: 299

    @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")
        scene.camera.z = -15
        scene.physics.gravity = vec3(0,0,0)
        r = e:add(craft.rigidbody,DYNAMIC)
    end
    
    function draw()
        r:applyForce(vec3(math.sin(ElapsedTime),math.cos(ElapsedTime),0)/4)
        scene:update(DeltaTime)
        scene:draw()
    end
    
  • dave1707dave1707 Mod
    Posts: 6,325

    @LoopSpace Add this line at the end of setup.

        r.sleepingAllowed=false
    
  • Posts: 299

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

  • RdoRdo
    edited October 26 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.