Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Resolved Rigidbody2D AddForce not moving object

Discussion in 'Physics' started by SkrenZz, Aug 19, 2020.

  1. SkrenZz

    SkrenZz

    Joined:
    Apr 11, 2020
    Posts:
    26
    Hello there,

    I am writing this thread after dealing with a very strange and frustrating issue. I am making a billiard game, and trying to make the cue ball move via adding a force to its Rigidbody2D when hit with the cue stick. The ball's mass is tiny, and I have increased the force multiplier to a ridiculously large number (currently at 5555), but the ball does not move at all despite having a very big velocity which is displayed in the inspector, please see attached image:
    upload_2020-8-19_20-6-44.png

    The following code is fired on the CueStick script when trigger enters cue ball:
    Code (CSharp):
    1.         Vector2 forceVector = new Vector2(
    2.             Mathf.Cos(this.transform.rotation.z * Mathf.Deg2Rad),
    3.             Mathf.Sin(this.transform.rotation.z * Mathf.Deg2Rad));
    4.         CueBall.Instance.Rigidbody.AddForce(forceVector * (this.force + 1f) * this.forceMultiplier, ForceMode2D.Impulse);
    5. // this.force is changed according to user input, and it ranges from 0 to 1.
    PS: There is another issue which currently is not the thing that bothers me most, but once I manage to get the cue ball to move, it will be very problematic (if I don't get both solved)- the velocity doesn't change at all, even though the ball's linear drag is 1.

    I will be very thankful to anyone who may try to help with this, I feel quite lost.
    Thanks a lot in advance, and have a wonderful day!
     
  2. SkrenZz

    SkrenZz

    Joined:
    Apr 11, 2020
    Posts:
    26
    Managed to find the cause of the problem. Had a line that moved the rigidbody2d position on every FixedUpdate.