I have a stardart sphere game object which is prefab with rigidbody and target script.
in target script Im giving circular movement to this sprere object.
And I have spawn script which accepts 3 point and 3 object which Instantiates theese 3 object in 3 point.
My circular movement is working, but when i try to add force through the camera it doesnt work.
How Can I achive both circular movement and add force through the camera?
My target and spawn scripts are below.
target
`
public class Target : MonoBehaviour
{
public float health = 50f;
public float speed;
public float width;
public float height;
float timeCounter = 0f;
Vector3 startPoint;
int direction;
void Start()
{
int number = Random.Range(1, 255);
direction = number % 2 == 0 ? 1 : -1;
startPoint = new Vector3(transform.position.x, transform.position.y, transform.position.z);
}
// Update is called once per frame
void Update()
{
timeCounter += Time.deltaTime * speed;
float x = direction * Mathf.Cos(timeCounter) * width + startPoint.x;
float y = Mathf.Sin(timeCounter) * height + startPoint.y;
float z = startPoint.z;
transform.position = new Vector3(x, y, z);
}
}`
spawn
`
public class SpawnScript : MonoBehaviour
{
public Transform spawnPoints;
public GameObject balloons;
void Start()
{
StartSpawn();
}
void StartSpawn()
{
for (int i = 0; i < spawnPoints.Length; i++)
{
GameObject target = Instantiate(balloons_, spawnPoints*.position, Quaternion.identity);*_
Rigidbody rbTarget = target.GetComponent();
rbTarget.AddForce(Camera.main.transform.position * 2f);
}
}
}`