Howdy, Stranger!

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

Gravity Help

Is there any possible way to make a 3D physics object become unaffected by gravity?? Like if the physics body type was DYNAMIC for instance, is there any way for it to become unaffected by gravity??

Thanks in advance :)

Comments

  • dave1707dave1707 Mod
    Posts: 9,977

    @Creator27 Make it KINEMATIC. Have you looked thru any of the builtin reference. You’ll find a lot of info there.

  • @dave1707, I have tried using KINEMATIC bodies and linear velocity but didn’t work. Could you possibly show me an example??

    Thanks :)

  • dave1707dave1707 Mod
    edited September 2021 Posts: 9,977

    Apparently you have to turn gravity off using scene.physics.gravity. But that affects all 3D objects.

    Or you can leave gravity on if you want to alter the direction it’s going under gravity.

    function setup()
        assert(OrbitViewer, "Please include Cameras (not Camera) as a dependency")
        size=1
        scene = craft.scene()
    
        scene.physics.gravity=vec3(0,0,0)
    
        skyMaterial=scene.sky.material
        skyMaterial.sky=color(0, 62, 255, 255)
        skyMaterial.horizon=color(99, 255, 0, 255)
        scene.sun.rotation=quat.eulerAngles(20,45,-30)
        createObjects()
        v=scene.camera:add(OrbitViewer, vec3(0,0,0), 30, 0, 200)
    end
    
    function createObjects()
        sphere2=scene:entity()
        s2=sphere2:add(craft.rigidbody,DYNAMIC)
        s2.linearVelocity=vec3(1,1,5)
        sphere2.position=vec3(0,0,0)
        sphere2.model = craft.model.icosphere(size,2)
        sphere2.material = craft.material(asset.builtin.Materials.Specular)
        sphere2.material.diffuse=color(0,0,255)
    end
    
    function draw()
        update(DeltaTime)
        scene:draw()    
    end
    
    function update(dt)
        scene:update(dt)
    end
    
  • Posts: 51
    Are you still not able to modify a kinematic bodies linear velocity in 3D? That should be in the documentation, because I was pretty confused for a bit.

    It’s a shame we can’t disable gravity on a per rigid-body basis too.
  • dave1707dave1707 Mod
    Posts: 9,977

    @arismoko I haven’t figured out the linearVelocity on a Kinematic body, must be a bug or not implemented. Here some code that will allow you to ignore collisions on Dynamic bodies. You can use Group and Mask to ignore collisions. Don’t know if that will help since you still have to ignore gravity on everything.

    viewer.mode=FULLSCREEN
    
    function setup()
        assert(OrbitViewer, "Please include Cameras (not Camera) as a dependency")
        scene = craft.scene()
    
        scene.physics.gravity=vec3(0,0,0)
    
        skyMaterial=scene.sky.material
        skyMaterial.sky=color(0, 62, 255, 255)
        skyMaterial.horizon=color(0, 255, 176)
        scene.sun.rotation=quat.eulerAngles(20,45,-30)
        createObjects(vec3(-5,0,0),vec3(1,0,0),2,2,1,color(255,0,0))
        createObjects(vec3(5,0,0),vec3(-1,0,0),2,1,2,color(0,255,0))
        v=scene.camera:add(OrbitViewer, vec3(0,0,0), 30, 0, 200)
    end
    
    function createObjects(pos,vel,grp,msk,size,c)
        sphere2=scene:entity()
        s2=sphere2:add(craft.rigidbody,DYNAMIC)
        s2.linearVelocity=vel
        s2.group=grp
        s2.mask=msk
        sphere2.position=pos
        sphere2.model = craft.model.icosphere(size,2)
        sphere2:add(craft.shape.sphere,size)
        sphere2.material = craft.material(asset.builtin.Materials.Specular)
        sphere2.material.diffuse=c
    end
    
    function draw()
        update(DeltaTime)
        scene:draw()  
    end
    
    function update(dt)
        scene:update(dt)
    end
    
Sign In or Register to comment.