function Car.setupBody ( ) -- local s = application.getCurrentUserScene ( ) if ( s ~= nil ) then -- Create body visual object -- local body = scene.createRuntimeObject ( s, this.sBodyModel ( ) ) this.hBody ( body ) if ( body == nil ) then log.error ( "Could not create car body" ) end -- Setup dyn on linked object (not the visual one) -- local o = this.getObject ( ) local sx = 1.50 local sy = 0.40 --0.90 local sz = 3.50 object.setParent ( body, o, 0 ) object.setUniformScale ( body, 1 ) -- object.setRotation ( body, 0, 90, 0, object.kParentSpace ) object.setTranslation ( body, 0, 0.5, 0, object.kParentSpace ) object.setTranslation ( o, 0, 2, 0, object.kGlobalSpace ) local spawner = scene.getTaggedObject ( s, "CarSpawn" ) if ( spawner ~= nil ) then local x, y, z = object.getTranslation ( spawner, object.kGlobalSpace ) object.setTranslation ( o, x, y, z, object.kGlobalSpace ) end if ( dyn.createBoxBody ( o, sx, sy, sz ) ) then dyn.setOffset ( o, 0, -0.15, 0 ) -- dyn.setCenterOfGravityOffset ( o, 0, -2, 0 ) dyn.setMass ( o, this.nBodyMass ( ) ) dyn.enable dyn ( o, 0 ) dyn.enableCollisions ( o, 0 ) dyn.enableGravity ( o, 0 ) dyn.setLinearDamping ( o, 0.00 ) dyn.setAngularDamping ( o, 0.00 ) dyn.setFriction ( o, 0.20 ) dyn.setBounce ( o, 0.50 ) end -- Create top bouncers (pure linked dynamic objets) -- local bodyBouncer = scene.createRuntimeObject ( s, "Dummy" ) local bodyBouncer2 = scene.createRuntimeObject ( s, "Dummy" ) this.hBodyBouncer ( bodyBouncer ) this.hBodyBouncer2 ( bodyBouncer2 ) local x, y, z = object.getTranslation ( o, object.kGlobalSpace ) object.setTranslation ( bodyBouncer, x, y + 0.6, z - 0.2, object.kGlobalSpace ) object.setTranslation ( bodyBouncer2, x, y + 0.7, z + 1.4, object.kGlobalSpace ) if ( dyn.createSphereBody ( bodyBouncer, 0.8 ) ) then dyn.setMass ( bodyBouncer, 1.00 ) dyn.enable dyn ( bodyBouncer, 0 ) dyn.enableCollisions ( bodyBouncer, 0 ) dyn.enableGravity ( bodyBouncer, 0 ) dyn.setLinearDamping ( bodyBouncer, 5.00 ) dyn.setAngularDamping ( bodyBouncer, 5.00 ) dyn.setFriction ( bodyBouncer, 3.00 ) dyn.setBounce ( bodyBouncer, 2.00 ) if ( dyn.createBallJoint ( bodyBouncer, o, "Link" ) ) then dyn.setBallJointAnchor ( bodyBouncer, "Link", 0, 0, 0, object.kLocalSpace ) end end if ( dyn.createSphereBody ( bodyBouncer2, 0.5 ) ) then dyn.setMass ( bodyBouncer2, 12.00 ) dyn.enable dyn ( bodyBouncer2, 0 ) dyn.enableCollisions ( bodyBouncer2, 0 ) dyn.enableGravity ( bodyBouncer2, 0 ) dyn.setLinearDamping ( bodyBouncer2, 5.00 ) dyn.setAngularDamping ( bodyBouncer2, 5.00 ) dyn.setFriction ( bodyBouncer2, 3.00 ) dyn.setBounce ( bodyBouncer2, 2.00 ) if ( dyn.createBallJoint ( bodyBouncer2, o, "Link2" ) ) then dyn.setBallJointAnchor ( bodyBouncer2, "Link2", 0, 0, 0, object.kLocalSpace ) end end end end