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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Manual physics update Not Applying

Discussion in 'Physics' started by EliJNemer, May 19, 2020.

  1. EliJNemer

    EliJNemer

    Joined:
    Aug 3, 2019
    Posts:
    123
    hello,

    i am having an issue with my applying manual physics update..

    in my script i have a ball and when i choose to shoot the ball a function StrikeBall() is called..

    this adds a velocity to the ball.. i do not want to add a force. i want to directly decide the velocities..

    in my update function i have a something which decreases the velocity of the ball a certain amount every FixedDeltaTime..

    and then i call Physics.simulate(time.FixeddeltaTime);

    but the ball is not moving..

    the in the debug the ball velocities are correct.. (it gives the velocity and decreases as expected)

    but the ball is not moving..

    here is my code:
    Code (CSharp):
    1. void Update()
    2.     {
    3.         if (!gotCueRotationManager)
    4.         {
    5.             GetCueRotationManager();
    6.         }
    7.  
    8.         DecreaseVelocities();
    9.         print(ballRB[0].velocity);
    10.        
    11.        
    12.         Physics.Simulate(Time.fixedDeltaTime);
    13.     }
    14.  
    15.  
    16.  
    17.  
    18.     public void StrikeBall()
    19.     {
    20.         print("striking Ball - Gamephysics");
    21.         ballRB[0].velocity = cueRotationManager.getForce();
    22.         BallDirections(cueRotationManager.getForce());
    23.     }
    24.  
    25.     public void DecreaseVelocities()
    26.     {
    27.         if(ballRB[0].velocity.magnitude >= 0.5f)
    28.         {
    29.             ballRB[0].velocity = new Vector3(ballRB[0].velocity.x - (ballDirections[0].x*Time.fixedDeltaTime), ballRB[0].velocity.y - ballDirections[0].y * Time.fixedDeltaTime, ballRB[0].velocity.z - ballDirections[0].z * Time.fixedDeltaTime);
    30.         }
    31.     }
     
  2. EliJNemer

    EliJNemer

    Joined:
    Aug 3, 2019
    Posts:
    123
    Found the Solution i was linking the RB Prefab not the Instantiated Version..