Hi,
I’m making a 2D game where you have to launch a sphere the way you launch birds in angry birds. I have done everything and I have clamped the position of the sphere before it launches on both X and Y axes. However, the result was that the ball was being clamped to a square region and this is not good because diagonal maximum distance is greater than straight maximum distance. I want to clamp the ball to a spherical area before it launches so maximum distance will be the same in all directions but I can’t think of what else to do.
Please, I urgently need this help. Any idea will be appreciated.
Hello. I am having this same issue. I figured out that Vector3.ClampMagnitude is what I need to use as well, but I’m not sure how to use it with mouse inputs. I think the example that Unity gives in it’s description is only for using it with keys. It says:
// Move the object around with the arrow keys but confine it
// to a given radius around a center point.
var centerPt: Vector3;
var radius: float;
function Update() {
// Get the new position for the object.
var movement = new Vector3(Input.GetAxis(“Horizontal”), 0, Input.GetAxis(“Vertical”));
var newPos = transform.position + movement;
// Calculate the distance of the new position from the center point. Keep the direction
// the same but clamp the length to the specified radius.
var offset = newPos - centerPt;
transform.position = centerPt + Vector3.ClampMagnitude(offset, radius);
}
If you could offer any advice on how to use this I would greatly appreciate it. Thanks.