object moves up when two opposing horizontal forces add up
so i'm working on a simple physics based game where i roll a ball on a plane and when i move forward and build up speed then move backwards the ball starts levetating up for some reason i tried freezing y axis when the ball is grounded but then it can't move up hills ,so here is the script n stuff
void Control_ball()
{
player_mesh.transform.position = transform.position;
float horizontal = Input.GetAxis("Horizontal");
float vertical = Input.GetAxis("Vertical");
float Xmov = horizontal * speed * Time.deltaTime;
float Zmov = vertical * speed * Time.deltaTime;
Vector3 dir = new Vector3(Xmov, 0, Zmov).normalized;
float targetangle = camera.transform.eulerAngles.y;
transform.rotation = Quaternion.Euler(0, targetangle, 0);
playerrb.AddRelativeForce(dir*speed,ForceMode.Acceleration);
playerrb.velocity = Vector3.ClampMagnitude(playerrb.velocity, max_speed);
player_mesh.transform.Rotate(dir * rollspeed);
}
Comment