Is anyone manage to do a perfect wheel joint

Hi All

 

Thanks for all your advices in advance

Could anyone point me to a right direction for wheeljoint?

 

there are none on the forum or the google. 

Threre is no one example how to do a simple car with the wheeljoint so it has a proper shock absorber of a car.

I have tried everything from the box2d original till the flash version box2D

and none of those example can be interpretered onto coronas physics.

I have not seen any suceesful examples or explonations. 

Is that mean corona is not supporting it or just I am a dum arse?

 

here is my tries

 

1: pJoints[1] = physics.newJoint( “wheel”, wheel1, body, wheel1.x,wheel1.y, 0,-70 )

2: pJoints[1].springFrequency  = 15

3: pJoints[1].springDampingRatio  = 0.5

if I set the axisDistanceY to any positive number the body just collapses onto the wheel

But even as i set this to -70 the wheel is not pivot around the center.

also springFrequency or springDampingRatio  has been set from all sorts of value  but none of the valuse i tried made any better.

I ve also tried to add the motor to the joints and that also did not made any different.

The test file give you more clue what i meant

Its so complex that I loosing it can anyone help me Please!

[lua]require “CiderDebugger”;-----------------------------------------------------------------------------------------
_W = display.viewableContentWidth
_H = display.viewableContentHeight

local wScale = 60 – world scale factor
local scale = 0.5 – change this to scale the car up or down
local wheelspace = 46*scale – sets the wheel position

local physics = require(“physics”)
physics.setScale( wScale )

local gameUI = require(“gameUI”) – you will need this to download from the net
physics.setDrawMode(“debug”)
physics.start()
physics.setGravity(0, 9.8)
– CREATE BACKGROUND
local bg = display.newRect(0, 0, _W, _H)
bg:setFillColor(11,114,125)
– CREATE FLOOR
local ground = display.newRect(0,0,_W,10)
ground:setFillColor(123,73,29)
ground.y = _H - ground.height * 0.5

physics.addBody(ground, “static”, {friction = 3,bounce=0})

– CREATE BOUNDARY WALLS (LEFT RIGHT)
local rwall = display.newRect(_W,0,_W,_H)
local lwall = display.newRect(0,0,20,_H)

physics.addBody(rwall,“static”, {friction=1})
physics.addBody(lwall,“static”, {friction=1})

– CREATE CAR

–body
local body = display.newRect(0,0,190*scale, 90*scale)
body.x = _W * 0.5
body.y = body.y + body.height

physics.addBody(body, “dynamic”,{density = 0.5,friction = 1,bounce=0.3,
filter = { categoryBits = 2, maskBits = 1, groupIndex = 1 }}
)
– wheels
local wheel1 = display.newCircle(0,0,21*scale)
wheel1.x = body.x-(wheelspace+5)
wheel1.y = body.y + body.height * 0.5

local wheel2 = display.newCircle(0,0,21*scale)
wheel2.x = body.x+(wheelspace-5)
wheel2.y = body.y + body.height * 0.5

physics.addBody(wheel1, “dynamic”, {density = 0.5,friction = 8,bounce=0.1,radius=21*scale,isSensor = false,
filter = {categoryBits = 2, maskBits = 1}})
physics.addBody(wheel2, “dynamic”, {density = 0.5,friction = 8,bounce=0.1,radius=21*scale,isSensor = false,
filter = {categoryBits = 2, maskBits = 1}})

–CREATE THAT STUPID WHEELJOINTS
– THE WHEEL DOES NOT PIVOT AROUND THE CENTER, more like locomotive piston movement
local pJoints = {}
pJoints[1] = physics.newJoint( “wheel”, wheel1, body, wheel1.x,wheel1.y, 0,-70 )
– the above settings are the most stable so far, but not acceptable . Its just a mess
– if the -70 value changed to any positive value its dissaster
pJoints[1].springFrequency = 10 – this value is best at 10
pJoints[1].springDampingRatio = 0.5 – this I have no clue but I have tried many different values too
pJoints[1].maxMotorTorque = 100000;

pJoints[2] = physics.newJoint( “wheel”, wheel2, body, wheel2.x,wheel2.y, 0,-70 )
pJoints[2].springFrequency = 15
pJoints[2].springDampingRatio = 0.5

– AN EVENT FUNCTION TO CONTROL THE CAR ENGINE

– haha ha ha its never works

–some reason the event gets fired but the engin wont start

local directionRight = true
local function startCar(event)
local body = event.target
local phase = event.phase

if “began” == phase then
pJoints[1].isMotorEnabled = true
if(directionRight) then
pJoints[1].motorSpeed = 400
directionRight = false
else
pJoints[1].motorSpeed = -400
directionRight = true
end
end
end

local dragBody = gameUI.dragBody
body:addEventListener(“touch”,dragBody)
wheel1:addEventListener( “touch”, startCar )
[/lua]

Hi @jollzy,

The wheel joint is a tricky one, and unfortunately I’m not an expert on this particular one. What I see in your code, initially, is that you’re trying to set values/properties that aren’t allowed on a wheel joint. While a wheel joint behaves “like a wheel on a shock absorber”, I don’t think you’ll get the shock absorber (bouncy spring-back) part automatically. Instead, you’d have to build that separately somehow, as a separate joint pulling back the “shock” part.

In any case, when dealing with joints, please refer to the following link to see how the properties work, and what they are named in Corona:

http://developer.coronalabs.com/content/game-edition-physics-joints

I wish I could help you further, but complicated joints like the “wheel” are fairly tricky, and you’ll need to continue experimenting to get the effect you want.

Regards,

Brent

jollzy, see this sample code:

http://developer.coronalabs.com/code/billy-cart-corona

I’ve played with that in the past and it might have some code that will help you.

 Jay

Hi @jollzy,

The wheel joint is a tricky one, and unfortunately I’m not an expert on this particular one. What I see in your code, initially, is that you’re trying to set values/properties that aren’t allowed on a wheel joint. While a wheel joint behaves “like a wheel on a shock absorber”, I don’t think you’ll get the shock absorber (bouncy spring-back) part automatically. Instead, you’d have to build that separately somehow, as a separate joint pulling back the “shock” part.

In any case, when dealing with joints, please refer to the following link to see how the properties work, and what they are named in Corona:

http://developer.coronalabs.com/content/game-edition-physics-joints

I wish I could help you further, but complicated joints like the “wheel” are fairly tricky, and you’ll need to continue experimenting to get the effect you want.

Regards,

Brent

jollzy, see this sample code:

http://developer.coronalabs.com/code/billy-cart-corona

I’ve played with that in the past and it might have some code that will help you.

 Jay

I followed this tutorial at http://lazywombat.co.uk/how-to-create-a-cart-with-box2d-and-corona-sdk/

it seems quite useful and quite easy to understand.

I followed this tutorial at http://lazywombat.co.uk/how-to-create-a-cart-with-box2d-and-corona-sdk/

it seems quite useful and quite easy to understand.