[Resolved] Changing direction of a physics object

Hi,

I have a racing car viewed from the top and using playerCar:setLinearVelocity to make it go forward (thanks Danny).

Now if I rotate it left/right I want it to go in that direction but can’t work out the calculation.

I thought the physics engine would handle this automatically but can’t seem to find a physics rotate type command. At the moment am changing the playerCar.rotation property.

I have created a spreadsheet to try and get the calculation right but can’t get it exact. I might get it working from 0 to 90 degrees but then it won’t work for other rotations.

Am sure there must be a simple solution for this but I have searched and can’t seem to find one.

Dave [import]uid: 117617 topic_id: 24375 reply_id: 324375[/import]

Maybe something like :

[code]
local speed = 100

object:setLinearVelocity(math.sin(math.rad(object.rotation)) * speed, math.cos(math.rad(object.rotation)) * -speed)
[/code] [import]uid: 84637 topic_id: 24375 reply_id: 98492[/import]

That works perfectly.

No wonder I couldn’t work it out, that is some crazy maths.

Thanks again.

Dave [import]uid: 117617 topic_id: 24375 reply_id: 98493[/import]

Glad to help :slight_smile: [import]uid: 84637 topic_id: 24375 reply_id: 98494[/import]