Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Instantiated object physics

Discussion in 'Physics' started by chainsawpenguin, Jan 6, 2019.

  1. chainsawpenguin

    chainsawpenguin

    Joined:
    Sep 28, 2014
    Posts:
    107
    When I instantiate a ragdoll after my target NPC is killed, it keeps lurching forwards toward my character, even though the same object created in blank space correctly flies away from its facing.

    Any ideas? Script below.



    Code (CSharp):
    1.   public Rigidbody mySpine1;
    2.     public Vector3 myForwardVector;
    3.     public Vector3 myUpVector;
    4.     public Vector3 myForceVector;
    5.     public float myBackForce = 500.0F;
    6.     public float myUpForce = 1000.0F;
    7.     public bool knockBackStarted;
    8.     public float startTime;
    9.     public float delayTime = 0.1F;
    10.  
    11.     void Start()
    12.     {
    13.         Destroy(gameObject, timeToLive);
    14.         startTime = Time.time;
    15.         knockBackStarted = false;
    16.     }
    17.  
    18.     void Update()
    19.  
    20.     {
    21.         if(Time.time >= startTime + delayTime && !knockBackStarted)
    22.         {
    23.             knockBackStarted = true;
    24.             myForceVector = myBackForce * Vector3.forward * -1.0F + myUpForce *  Vector3.up;
    25.             mySpine1.AddForce(myForceVector);
    26.  
    27.         }
    28.     }
     
    Last edited: Jan 7, 2019
  2. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    5,226
unityunity