I’m new to phaser and matterjs but I’m trying to simulate a rear wheel drive car from a top view. Each wheel has its own motor, so if Left wheel has 100% power and Right wheel has -100% power, the car would spin clockwise around the wheel axle. How would one go about and simulate something like this?
I actually managed to get something that works by rotating the car body around each wheel in the update() loop:
// Calculate position of left wheel
var leftWheelPos = {x:car.x - wheelXOffset, y:car.y + wheelYOffset};
Phaser.Math.RotateAround(leftWheelPos, car.x, car.y, car.rotation)
leftWheel.setPosition(leftWheelPos.x, leftWheelPos.y);
// Rotate car around left wheel
car.rotation -= maxRot * rightPower
Phaser.Actions.RotateAround([car], leftWheel, -maxRot * rightPower)
// Calculate position of right wheel
var rightWheelPos = {x:car.x + wheelXOffset, y:car.y + wheelYOffset}
Phaser.Math.RotateAround(rightWheelPos, car.x, car.y, car.rotation)
rightWheel.setPosition(rightWheelPos.x, rightWheelPos.y);
// Rotate car around right wheel
car.rotation += maxRot * leftPower
Phaser.Actions.RotateAround([car], rightWheel, maxRot * leftPower)
It works but it seems like a hack and it feels like I’m bypassing the physics engine by doing the rotation of the car manually. What would be the proper way to do something like this?