I had migrated my game right well, but I noticed something extrange, my game is a top down car game with physics, so if I run game in hybrid mode I can see the lines of joints from wheels to the body moving with the car perfectly, but when I migrated to graphics 2.0 joints lines does not move correctly, only in the top left corner body shapes and joint lines seems to match, but when moving car joint lines move out of car.
This is an image showing how when I move the car the joint lines do not moves acorde to the body.
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()
wheel = Wheel:new() --returns a wheel instance
wheel.object has the physic display object created
local myJoint = self:createJoint (params\_join)
this creates a joint of the parameter type:
if(paramsJoint.type == "pivot") then local object1 = self.tabObjects[paramsJoint.obj1] local object2 = self.tabObjects[paramsJoint.obj2] local anchorX1 = paramsJoint.anchorX1 local anchorY1 = paramsJoint.anchorY1 local anchorX2 = paramsJoint.anchorX2 local anchorY2 = paramsJoint.anchorY2 if(object1 and object2 and anchorX1 and anchorY1 and anchorX2 and anchorY2) then jointInstance = physics.newJoint( "pivot", object1.object, object2.object, anchorX1, anchorY1,anchorX2, anchorY2 ) paramsJoint.instance = jointInstance self.tabJoints[paramsJoint.name] = paramsJoint elseif(object1 and object2 and anchorX1 and anchorY1) then jointInstance = physics.newJoint( "pivot", object1.object, object2.object, anchorX1, anchorY1 ) paramsJoint.instance = jointInstance self.tabJoints[paramsJoint.name] = paramsJoint end
Hi @miralles.sergio,
Did you experiment with running this in V1 Compatibility mode vs. normal? My guess is that this is related to anchor points and positioning. Please test both modes and report back the variances.
http://docs.coronalabs.com/guide/graphics/migration.html
Sincerely,
Brent Sorrentino
Set V1 Compatibility mode do not solve the problem.
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()
wheel = Wheel:new() --returns a wheel instance
wheel.object has the physic display object created
local myJoint = self:createJoint (params\_join)
this creates a joint of the parameter type:
if(paramsJoint.type == "pivot") then local object1 = self.tabObjects[paramsJoint.obj1] local object2 = self.tabObjects[paramsJoint.obj2] local anchorX1 = paramsJoint.anchorX1 local anchorY1 = paramsJoint.anchorY1 local anchorX2 = paramsJoint.anchorX2 local anchorY2 = paramsJoint.anchorY2 if(object1 and object2 and anchorX1 and anchorY1 and anchorX2 and anchorY2) then jointInstance = physics.newJoint( "pivot", object1.object, object2.object, anchorX1, anchorY1,anchorX2, anchorY2 ) paramsJoint.instance = jointInstance self.tabJoints[paramsJoint.name] = paramsJoint elseif(object1 and object2 and anchorX1 and anchorY1) then jointInstance = physics.newJoint( "pivot", object1.object, object2.object, anchorX1, anchorY1 ) paramsJoint.instance = jointInstance self.tabJoints[paramsJoint.name] = paramsJoint end
Hi @miralles.sergio,
Did you experiment with running this in V1 Compatibility mode vs. normal? My guess is that this is related to anchor points and positioning. Please test both modes and report back the variances.
http://docs.coronalabs.com/guide/graphics/migration.html
Sincerely,
Brent Sorrentino
Set V1 Compatibility mode do not solve the problem.