Rolling a ball forward with AddForce depending on the track direction
I have a ball that moves forward alone, the player only has to turn left or right to get the gems and not falling of the road.
The problem is that I use a function called AddForce to push the ball forward but I don't know how to adapt the direction depending on the direction of the track. If there is a left turn for exemple, I want my ball to take the turn by it self an readapt to the track keeping the camera to follow behind.
void FixedUpdate()
{
float moveHorizontal = Input.GetAxis("Horizontal") * sideSpeed * rb.velocity.magnitude / acceleration;
if (rb.velocity.magnitude <= speedLimit)
{
rb.AddForce(0.0f, 0.0f, acceleration); // add vertical force
}
rb.AddForce(moveHorizontal, 0.0f, 0.0f); // add horizontal force
}
2019-01-25-2.png
(337.1 kB)
Comment