Search Unity

Properly resetting forces

Discussion in 'Scripting' started by ManAmazin, Dec 21, 2014.

  1. ManAmazin

    ManAmazin

    Joined:
    Aug 7, 2013
    Posts:
    246
    Hey guys so im using a pooling system for the first time and having some issues with the projectile. Since it doesn't actually Destroy the object i was told i needed to zero out the forces and whatnot ive tried two way which didnt yield the results needed

    Code (CSharp):
    1.      if (col.gameObject.name != "PlayerOne" && col.gameObject.tag == "BackWall")
    2.         {
    3.             scoring.score -= 100;
    4.             scoring.Currency -= 5;
    5.             TouchedPlayer();
    6.             RemovePrefab();
    7.         }
    8.     }
    9.  
    10.  
    11.     public void Attack()
    12.     {
    13.         transform.rigidbody.AddForce(transform.forward * speed * Time.smoothDeltaTime);
    14.         //transform.rigidbody.velocity = transform.forward * speed * Time.deltaTime;
    15.         //transform.Translate(Vector3.forward * speed * Time.smoothDeltaTime);
    16.     }
    17.  
    18.     public void RemovePrefab()
    19.     {      
    20.         if(gameObject.rigidbody.isKinematic == false)
    21.         {
    22.             gameObject.rigidbody.isKinematic = true;                      
    23.         }
    24.         gameObject.DestroyAPS();
    25.                
    26.     }
    so when the projectile is reactivated it has really weird behavior such as going in circles, going straight up then coming down etc


    any help much appreciate it .
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Set the velocity and angularVelocity to zero.

    --Eric
     
  3. ManAmazin

    ManAmazin

    Joined:
    Aug 7, 2013
    Posts:
    246
    hey eric thats what i had at first and didnt work maybe i was doing it wrong. should i do it instead of, or in conjunction with the "isKinematic" as i have above?
     
  4. ManAmazin

    ManAmazin

    Joined:
    Aug 7, 2013
    Posts:
    246
    anyone?