I am trying to make cloned balls start moving away from their spawner. How can I make my script work?

using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Threading;
using UnityEngine;

public class InitialVelocity : MonoBehaviour
    public Vector3 direction;
    public GameObject Player;
    void Start()
        direction = transform.position - Player.transform.position;

//With this script, my cloned balls all move in the same direction, while they should move in different directions depending on their position relative to their spawner (Player).

First off, in the future when displaying code on unity answers, make sure you use the code input feature, represented by an icon with 0s and 1s. Next, at this line


GetComponent() by itself does nothing, I assume you want the rigidbody component, which has the method AddForce(). So instead what you would do is this:


Notice that I don’t use parentheses, I use these <>. Let me know if you need anything else!