ah ok, well you weren’t terribly precise in your explanation, but this was also worth learning, no?
ok, then the solution is completely different.
you need a ground floor, which you probably already have, but it needs to have a rigidbody on it, and a box collider.
turn this object static, so that it doesn’t try to move and bother the rest of the physics. maybe you already have this set up.
then you want to shoot a ray from your camera to your mouse. try to find a solution for that on the forum, so that we can fast forward to the good stuff. basically you shoot a ray, that ray hits the ground, the point where you hit the ground is the point where the mouse is pointing at.
to make it avoid hitting other objects you set different “layers” of collision, and then you make ground on its own layer. so that when you shoot the ray you can tell it to be affected only by this ground layer.
check out the docs on this, there are examples as well
next, once we have this coordinate, this is the coordinate towards which the wall wants to rotate. right? I hope I haven’t misread your question again this time. so the wall should always get in between the ball and the mouse pointer.
ok, to do this, you need two points. one point is the center of the ball itself, the other is the hit point on the ground. notice that this ground point is lower than the ball center, so we’ll ignore that kind of down tilt when we rotate. we want to rotate the wall only around the Y axis, am I right?
so two points, ballPoint and mousePoint. both will have x, y, z coordinates, but we’ll disregard the y.
if you subtract mousePoint by ballPoint you’ll get the vector (imagine an arrow) that points from the ball to the mouse.
to position the wall on the circle around the ball, you could use the normalization of this vector, multiplied by some distance value. to rotate the wall accordingly you could use Quaternion.AngleAxis and supply the angle and the up orientation as the axis.
or you could just call the wall’s transform and call LookAt method, which is the preferred method, simply because it’s easier.
var coord = hit.position; // suppose that we got this via RayCast
wall.transform.LookAt(coord, Vector3.up);
// this 'Vector3.up' is so that it has a concept of what should remain 'up' after rotation, otherwise it might tumble sideways
but wait, if your wall’s center isn’t at the same height, this might tilt it anyways.
so let’s just make sure that it’s on the same height
var coord = hit.position;
coord.y = wall.transform.position.y;
wall.transform.LookAt(coord, Vector3.up);
but we could use that normalization anyway to position the wall nicely.
var coord = hit.position;
var norm = (coord - wall.transform.position).normalized;
coord.y = wall.transform.position.y;
wall.transform.position = distance * norm; // try to replace distance with 1f, 2f, 3f ...
wall.transform.LookAt(coord, Vector3.up);
for this to work properly, you don’t have to set parent of wall’s transform to a ball’s transform.
but if you do, it’ll still work, because we force its world position to a proper position regardless of the hierarchy.
if the wall isn’t oriented properly, it’s original orientation should be set so that this mouse position is hypothetically in the direction of the blue arrow (forward). also make sure its bottom center lies on (0,0,0) in its local space.