Car physics, help required to translate some Box2d code

Hi,
 
Okay so i got a top down car behavior nearly working, I made it using a tutorial with box2d in ActionScript 3.
The link : http://www.emanueleferonato.com/2009/04/06/two-ways-to-make-box2d-cars/

I’m struggling to find the equivalent of some pieces of code in corona.

//This function applies a "friction" in a direction orthogonal to the body's axis. function killOrthogonalVelocity(targetBody:b2Body){ var localPoint = new b2Vec2(0,0); var velocity:b2Vec2 = targetBody.GetLinearVelocityFromLocalPoint(localPoint); var sidewaysAxis = targetBody.GetXForm().R.col2.Copy(); sidewaysAxis.Multiply(b2Math.b2Dot(velocity,sidewaysAxis)) targetBody.SetLinearVelocity(sidewaysAxis);//targetBody.GetWorldPoint(localPoint)); }

 
How would i get the velocity from a local point of one wheel?
 
The other sample:

var ldirection = leftWheel.GetXForm().R.col2.Copy(); ldirection.Multiply(engineSpeed); var rdirection = rightWheel.GetXForm().R.col2.Copy() rdirection.Multiply(engineSpeed); leftWheel.ApplyForce(ldirection, leftWheel.GetPosition()); rightWheel.ApplyForce(rdirection, rightWheel.GetPosition());

I don’t really understand how would i do the GetXForm function on a body, looks like it returns a vector but which kind, and what is the equivalent?

Thanks in advance :wink:

Max.

There is no such freedom in corona. You must communicate with box2d through corona api. Check physics.* api docs

Yes, it’s what i did for the rest of the implementation.

The only thing i keep struggling with is those two questions, i came here because i found no reference at all in the physics api docs, maybe missed it.

As I dont know what means getting an xform of a body, i wonder first what it is, and second if theres an equivalent through corona api.

In documentation is evereything accessible - you can say that just this.

You can only get velocity of object and apply force for what you want. You do not have direct access to box2d api - Corona goal was to simplify things so you do not have to burden yourself - however it arises problems when you want to do advanced/core stuff  like for eg vector math - you just can’t (at least at free versione - paid ones gives you more access so maybe there is a way). The only way is to implement some vector logic code on lua level and manage it yourself.

Okay I get it thank you, I figured a solution for the wheel impulse by giving a velocity from the angle of the joint it seems to work decently. I’ll have to figure out the killOrthogonalVelocity but that should be fine , thank you for the clarification.

Max

There is no such freedom in corona. You must communicate with box2d through corona api. Check physics.* api docs

Yes, it’s what i did for the rest of the implementation.

The only thing i keep struggling with is those two questions, i came here because i found no reference at all in the physics api docs, maybe missed it.

As I dont know what means getting an xform of a body, i wonder first what it is, and second if theres an equivalent through corona api.

In documentation is evereything accessible - you can say that just this.

You can only get velocity of object and apply force for what you want. You do not have direct access to box2d api - Corona goal was to simplify things so you do not have to burden yourself - however it arises problems when you want to do advanced/core stuff  like for eg vector math - you just can’t (at least at free versione - paid ones gives you more access so maybe there is a way). The only way is to implement some vector logic code on lua level and manage it yourself.

Okay I get it thank you, I figured a solution for the wheel impulse by giving a velocity from the angle of the joint it seems to work decently. I’ll have to figure out the killOrthogonalVelocity but that should be fine , thank you for the clarification.

Max