Turning off gravity

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

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

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

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

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.

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

@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

@LoopSpace Add this line at the end of setup.

    r.sleepingAllowed=false

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

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.