
:D
This is a really good idea! Thanks!
The implementation contains some nuances:
Input.mousePosition return pixel coordinates. It needs to be converted to virtual coordinates.
// Moving player to left and right
void MovePlayer()
{
// Get mouse position in pixel-coordinate system and transform it to virtual-coordinate system
Ray mouseRay = camera.ScreenPointToRay(Input.mousePosition);
mouseX = mouseRay.GetPoint(10f).x;
if (gameManager.isGameActive)
{
if (mouseX < leftBound)
{
positionX = leftBound;
}
else if (mouseX > rightBound)
{
positionX = rightBound;
}
else
{
positionX = mouseX;
}
playerRb.MovePosition(new Vector3(positionX, playerPosY, playerPosZ));
}
}
The project has updated. You can test it.
Added a link to you in devlog ;)
I just set the high "Horse Power" (25000). For this course, this is an acceptable solution. I was interested in this question and I found a good video demonstrating the implementation of the car.
As a quick fix, I used WheelCollider.motorTorque:
// Remove force from the car
// playerRb.AddRelativeForce(Vector3.forward * horsePower * forwardInput);
// Add motor torque to the wheels
foreach (var wheel in wheels)
{
wheel.motorTorque = horsePower * forwardInput;
}
This gives a more correct behavior to the car.
Sorry for my English, I use Google Translate :)
Good implementation. But the car moves back and forth with respect to the global coordinate system. If you use the AddForce method to move forward, try replacing it with AddRelativeForce ;)