I use OOP so I have an object and a wheel classes, next I past the code in car class in which wheels and joints are created:
-- Create body local params\_physics = physicsData:get(params.model) params\_physics.bounce = components.chasis.bounce or 0.1 --Force feecback params\_physics.density = self.mass / 1000 --To calculate mass of object params\_physics.friction = components.chasis.friction or 0.5 --friction when rubbing agaisnt other shapes params\_physics.isbullet = true --dedicates more time to collision detection - car travelling at high speeds at low framerates otherwise might teleport through obstacles. params\_physics.linearDamping = components.aerodinamics.linearDamping or 0.5 -- simulates friction of AIR params\_physics.angularDamping = components.aerodinamics.angularDamping or 0.5 -- stops CAR from spinning forever local params\_carrace = {} params\_carrace.entityParent = self params\_carrace.name = 'body' params\_carrace.type = "IMAGE" params\_carrace.x = params.x params\_carrace.y = params.y params\_carrace.width = components.chasis.width params\_carrace.height = components.chasis.height params\_carrace.blendMode = params.blendMode or "normal" params\_carrace.rotation = 0 params\_carrace.initialRotation = self.initialRotation params\_carrace.alpha = params.alpha or 1 params\_carrace.gradient = nil params\_carrace.pathImage = resources.cars[self.model] params\_carrace.displayGroupParent = self.layer params\_carrace.hasBody = true params\_carrace.isDraggable = params.isDraggable params\_carrace.dragDamping = 0.7 params\_carrace.dragMaxForce = 1000 params\_carrace.dragFrequency = 50 params\_carrace.params\_physics = params\_physics local body = Object:new(params\_carrace) self.body = body self:addObject (body) body.object:setFillColor(self.color[1],self.color[2],self.color[3]) ---------------------------------------------------------------------------------- ---- WHEELS --------------------------------------------------------------------------------- -- Wheels object params local params\_wheel = { model = self.components.wheels, car = self, } -- Left Frontal wheel params\_wheel.name ='leftFrontalWheel' params\_wheel.x = body.object.x - body.object.width \* 0.5 + components.wheels.width \* 0.5 params\_wheel.y = body.object.y - (body.object.height \* 0.4) + components.wheels.height \* 0.5 params\_wheel.powered = (self.traction == 'F' or self.traction == '4') params\_wheel.revolute = true local wheel = Wheel:new(params\_wheel) self:addObject (wheel) self.wheels[#self.wheels+1] = wheel local leftFrontalWheel = wheel -- Right Frontal wheel params\_wheel.name ='rightFrontalWheel' params\_wheel.x = body.object.x + body.object.width \* 0.5 - components.wheels.width \* 0.5 params\_wheel.y = body.object.y - (body.object.height \* 0.4) + components.wheels.height \* 0.5 params\_wheel.revolute = true local wheel = Wheel:new(params\_wheel) self:addObject (wheel) self.wheels[#self.wheels+1] = wheel local rightFrontalWheel = wheel -- Left Rear wheel params\_wheel.name ='leftRearWheel' params\_wheel.x = body.object.x - body.object.width \* 0.5 + components.wheels.width \* 0.5 params\_wheel.y = body.object.y + (body.object.height \* 0.4 ) - components.wheels.height \* 0.5 params\_wheel.powered = (self.traction == 'T' or self.traction == '4') params\_wheel.revolute = false local wheel = Wheel:new(params\_wheel) self:addObject (wheel) self.wheels[#self.wheels+1] = wheel local leftRearWheel = wheel -- Right Rear wheel params\_wheel.name ='rightRearWheel' params\_wheel.x = body.object.x + body.object.width \* 0.5 - components.wheels.width \* 0.5 params\_wheel.y = body.object.y + (body.object.height \* 0.4) - components.wheels.height \* 0.5 params\_wheel.revolute = false local wheel = Wheel:new(params\_wheel) self:addObject (wheel) self.wheels[#self.wheels+1] = wheel local rightRearWheel = wheel -- Set powered wheels for i=1, #self.wheels do wheel = self.wheels[i] if wheel.powered then self.poweredWheels[#self.poweredWheels+1] = wheel end if wheel.revolute then self.revoluteWheels[#self.revoluteWheels+1] = wheel end end local maxSteerAngle = self.setup.maxSteerAngle ------------------------------------------------ -- Frontal powerded and revoluted ------------------------------------------------ local params\_join = { name = 'jointLeftFrontalWheel', type = "pivot", obj2= leftFrontalWheel.name, obj1= body.name, anchorX1 = leftFrontalWheel.object.x, anchorY1 = leftFrontalWheel.object.y, } local myJoint = self:createJoint (params\_join) myJoint.isLimitEnabled = true -- (boolean) myJoint:setRotationLimits( maxSteerAngle \* -1, maxSteerAngle ) local params\_join = { name = 'jointRightFrontalWheel', type = "pivot", obj2= rightFrontalWheel.name, obj1= body.name, anchorX1 = rightFrontalWheel.object.x, anchorY1 = rightFrontalWheel.object.y, } local myJoint = self:createJoint (params\_join) myJoint.isLimitEnabled = true -- (boolean) myJoint:setRotationLimits( maxSteerAngle \* -1, maxSteerAngle ) ------------------------------------------------ -- Rear fixed wheels ------------------------------------------------ local params\_join = { name = 'jointLeftRearWheel', type = "weld", obj2= leftRearWheel.name, obj1= body.name, anchorX1 = leftRearWheel.object.x, anchorY1 = leftRearWheel.object.y, } self:createJoint (params\_join) local params\_join = { name = 'jointRightRearWheel', type = "weld", obj2= rightRearWheel.name, obj1= body.name, anchorX1 = rightRearWheel.object.x, anchorY1 = rightRearWheel.object.y, } self:createJoint (params\_join) -- Sends body to front of dysplay body.object:toFront()