Changing position.Translate to rb.AddForce
Hello guys,
I am making a small infinite runner game where the player is a TukTuk and needs to avoid cars coming in the opposite direction.
Key Points:
The camera movement is independent from the player movement.
The player is supposed to have the same default speed than the camera's, but he can speed up/down within the span of the camera POV.
That was working correctly when I was moving my player with "transform.Translate", but now I am trying to improve the physics by applying AddForce to my player's Rigibody. This is a mess to keep the player at the same speed than the camera.
CameraController:
transform.position += (Vector3.forward * Time.deltaTime * speed);
PlayerController (when it worked properly):
verticalInput = Input.GetAxis("Vertical");
float verticalInputMinMax = 0f;
if (verticalInput >= 0) verticalInputMinMax = verticalInput + 1.0f;
if (verticalInput < 0) verticalInputMinMax = verticalInput;
transform.Translate(Vector3.forward * Time.deltaTime * cameraSpeed * verticalInputMinMax);
I have tried a bunch of stuff with AddForce, but nothing successful. Do you guys have any idea or tips for me please ? =)
EDIT: Sorry I cannot seem to figure out how to return to line :/