Thanks for your help but I found out what was causing it, turned out an object needs a certain amount of mass to rotate
Here is a beta of the driving game I'm working on
At the moment the transitions are a little funny.
Which brings me onto a new question to all you mathematicians out there!
In this image the yellow box is the cars body.
The 2 red circles are the wheels and the red crosses are where I want the wheels to be. I need to find the position of those 2 red crosses.
Code: Select all
function createplayer(velx, vely, x, y, ang)
clearplayer()
if not ply.car_bod then
ply.car_bod = phys.newBody(world, x, y, 500)
else
ply.car_bod:setPosition(x,y)
end
ply.wheeldiam = 30
ply.wheelimg = love.graphics.newImage("images/wheel.png")
ply.whl1_bod = phys.newBody(world, x + 50, y, 300)
ply.whl2_bod = phys.newBody(world, x - 50, y, 300)
ply.whl1 = phys.newCircleShape(ply.whl1_bod, ply.wheeldiam)
ply.whl2 = phys.newCircleShape(ply.whl2_bod, ply.wheeldiam)
ply.whl1_bod:setAngularDamping( 2 )
ply.whl2_bod:setAngularDamping( 2 )
ply.whl1_bod:setMassFromShapes()
ply.whl2_bod:setMassFromShapes()
ply.car_rect = phys.newRectangleShape(ply.car_bod,0,0, 150, 10)
ply.car_bod:setAngle(ang)
--ply.car_rect2 = phys.newRectangleShape(ply.car_bod,0,-30, 40, 50,00)
ply.car_bod:setMassFromShapes()
ply.jnt1 = phys.newRevoluteJoint( ply.whl1_bod, ply.car_bod, ply.whl1_bod:getX(),ply.whl1_bod:getY() )
ply.jnt2 = phys.newRevoluteJoint( ply.whl2_bod, ply.car_bod, ply.whl2_bod:getX(),ply.whl2_bod:getY() )
ply.whl1:setFriction( 2 )
ply.whl2:setFriction( 2 )
ply.car_bod:setVelocity(velx, vely)
end
That is the code for creating the player. When a transition to the next slide happens. the thing is when yo set the angle to other than 0 the wheels dont follow they are positioned as if the body was at angle 0. I really need help with this I don't know enough about trig/vector math to get my head round it
Thanks.