How do I apply a physical force to an object?

Hey guys,
What I want to do is apply a force to an object in the direction the player is facing.
So effectively almost throwing/dropping an item.

So basically:

        if (Input.GetKey("q") && isholding == true)
        {
            DropItem();
        }

Any help is appreciated! I’m not too familiar with the physics engine and API regarding physics in Unity. Only used rigidbodies to apply gravity to objects :smile:

You can try to use AddForce to an or modify velocity of an rigidbody.

Or you can do the calculations of the way yourself and change position of an object with MoveTowards

So I’ve done this so far:

    public float thrust;
    public Rigidbody rb;

  void Start()
    {
        rb = GetComponent<Rigidbody>();
    }

   void Update()
    {
        if (Input.GetKey("q") && isholding == true)
        {
            DropItem();
            rb.AddForce(transform.forward * thrust);
        }
    }

Applied a thrust value in the inspector and dragged the rigid body of the object I want to manipulate into the inspector.

Without implementing any of the forward thrust everything was fully operational.
However sometimes when the object is “thrown” I can’t pick it back up, is there any reason for this?

We would have to see the code being used to pick it up in order to be able to answer that.

    void OnTriggerStay(Collider other)
    {
        // If the entering collider is a book...
        if (other.gameObject.tag == "book" && Input.GetKey("e"))
        {
            itemweight = 1.2f;
            ScoreManager.currentweight += itemweight;
            bookimage.color = visible;
            isholding = true;
            Color c = bookweightA.color;
            c.a = 100;
            bookweightA.color = c;
            bookweightA.CrossFadeAlpha(0, 2, false);
            Destroy(other.gameObject);
        }
        // If the entering collider is a map...
        else if (other.gameObject.tag == "map" && Input.GetKey("e"))
        {
            itemweight = .2f;
            ScoreManager.currentweight += itemweight;
            mapimage.color = visible;
            isholding = true;
            Color c = mapweightA.color;
            c.a = 100;
            mapweightA.color = c;
            mapweightA.CrossFadeAlpha(0, 2, false);
            Destroy(other.gameObject);
        }

        else if (other.gameObject.tag == "wand" && Input.GetKey("e"))
        {
            itemweight = .5f;
            ScoreManager.currentweight += itemweight;
            wandimage.color = visible;
            isholding = true;
            //Color c = mapweightA.color;
            //c.a = 100;
            //mapweightA.color = c;
            //mapweightA.CrossFadeAlpha(0, 2, false);
            Destroy(other.gameObject);
        }
        else
        {
        }
    }

       
    void DropItem()
    {
        if (bookimage.color == visible)
        {
            itemweight = 1.2f;
            ScoreManager.currentweight -= itemweight;
            bookimage.color = invisible;
            Vector3 position = GameObject.Find("CollectableSpawnPoint").transform.position;
            GameObject GO;
            GO = Instantiate(book, position, Quaternion.identity) as GameObject;
        }

        if (mapimage.color == visible)
        {
            itemweight = .2f;
            ScoreManager.currentweight -= itemweight;
            mapimage.color = invisible;
            Vector3 position = GameObject.Find("CollectableSpawnPoint").transform.position;
            GameObject GO;
            GO = Instantiate(map, position, Quaternion.identity) as GameObject;
        }

       if (wandimage.color == visible)
        {
            itemweight = .5f;
            ScoreManager.currentweight -= itemweight;
            wandimage.color = invisible;
            Vector3 position = GameObject.Find("CollectableSpawnPoint").transform.position;
            GameObject GO;
            GO = Instantiate(wand, position, Quaternion.identity) as GameObject;
        }
       
        isholding = false;
    }