Shooting around defense position without contact

Greetings

I would like to ask about a vector shooting in a 0 gravity environment with a 2D perspective.

I have a defense point in 0,0,0 while I’m shooting rocks from a launcher that rotates it’s z with a 360 * random.value, this makes it circulate around the defense point.

I would like to define two shooting methods, one that shoots straight to 0,0,0 and one shooting close to the middle but always avoiding the defense point at 0,0,0 (and the area it covers, let’s say a 1,1,1 cube).

Right now, I’m using rigidbody.AddForce with impulse, the vector is a Vector3(-transform.position.x, -transform.position.y, 0), this way I get it to shoot to the defense point but I am wondering if I can get this to work other way.

Many thanks

I’m not exactly clear on your implementation, but if I understand correctly, it seems like you want an offset from a target to shoot at.

You could simply do something like:

Transform targetTransform;
Vector3 target = targetTransform.position;
Vector3 offset = Vector3.up;

void Shoot()
{
    rigidbody.AddForce(offset - transform.position);
}

this code would make it so that if your targetTransform is at (0, 0, 0), you will add an offset of (0, 1, 0) to it, and your current object will havea force applied to it that aims directly at (0, 1, 0).

Hope that helps.