Move an object away from a moving object.

using UnityEngine;
using System.Collections;

public class BulletMod : MonoBehaviour {

	private float lifeTIme;

	private GameObject Objectcenter;

	public GameObject bullet;

	void maxBulletLife()
	{
		lifeTIme += Time.deltaTime;

		if (lifeTIme >= 5.0f) 
		{
			Destroy(this.gameObject);
			lifeTIme = 0.0f;
		}
	}

	void bulletFIRE()
	{

		Objectcenter = GameObject.FindGameObjectWithTag ("Circleshot");
	if (bullet != null) 
	{
		GameObject objCen = Objectcenter;
		Vector3 centerPos = objCen.transform.position;
		rigidbody.centerOfMass = objCen.transform.position;
		rigidbody.AddForce(transform.position - centerPos,ForceMode.Force);

	}
	}

	
	// Update is called once per frame
	void Update () 
	{
		maxBulletLife ();
		bulletFIRE ();
	}
}

That’s currently what happens, The object in front is what I want the result to be, which it does, but the objects in the back aren’t doing what the object in front is.

1- The objects in the back are instantiated objects.

2- The object in front starts to follow the same pattern as the objects in the back if it is moved.

3- I have a Rigidbody attached to the Bullet object, gravity is disabled, and Translate(Z) is frozen.

EDIT: Changed the code a bit, it looks a lot better this way, but again it only seems to want to effect the front object.

Is there a way I can make it effect all the objects in the scene?

And it fix’d it for the object already in the scene, I can now move it and the other objects with be sent in the correct direction,

But the objects that are instantiated are still having the same issue.


using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class bSpawner : MonoBehaviour {

	public GameObject Bullet;
	public GameObject center;
	public GameObject bClone;
	public Transform sPos;

	public int numberOfObjects = 20;
	public float radius = 5;

	public bool alive;

	public float lifeTime;

	//public List<GameObject> bList = new List<GameObject>();

	void Live()
	{
		float speed = 5.0f * Time.deltaTime;
		float yPos = center.transform.position.y;

		for (int i = 0; i < numberOfObjects; i++) 
		{
			float angle = i * Mathf.PI * 2 / numberOfObjects;
			Vector3 pos = new Vector3 (Mathf.Cos (angle),Mathf.Sin (angle),0) * radius;
			Vector3 thisPos = center.transform.position;
			Quaternion thisRot = center.transform.rotation;
			Vector3 cenPos =center.transform.position;
			cenPos = rigidbody.worldCenterOfMass;
			bClone = Instantiate (Bullet,thisPos - pos, thisRot) as GameObject;
			bClone.transform.position = Vector3.MoveTowards(thisPos ,thisPos- pos,-5.0f * speed);
		}

	}
	
	void Update () 
	{
		lifeTime += Time.deltaTime;
		if (alive) 
		{
			Live ();
			alive = false;
		}
		if (lifeTime >= 1.0f) 
		{
			alive = true;
			Destroy(bClone);
			lifeTime = 0.0f;
		}
	
	}
}

Now that works to some extent, my only issue is there is a little glitch on the bottom lefthand corner.

Was wondering if anyone could check to see for a possible fix to that?

Center is the circle object

Bullet is the thing being instantiated and of course bClone is the clone.

sPos can be ignored since it isn’t used.