Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Adding bullet force in the Zombie tutorial game

Discussion in 'Getting Started' started by Cameltotem, Feb 16, 2015.

  1. Cameltotem

    Cameltotem

    Joined:
    Feb 16, 2015
    Posts:
    5
    Hello! I've been creating my own version of the game, creating a new map, adding jump function to player, new weapons and particle systems. However I can't seem to make bullet force work in the game, what I essentially want to do is shoot an object and make it affected by the physics/rigidbody.

    Tried some different types.



    Code (CSharp):
    1.  
    2.     if(shootHit.rigidbody)
    3.     {
    4.         shootHit.rigidbody.AddForceAtPosition(transform.forward * 5,shootHit.point);
    5.     }
    6. */
    Code (CSharp):
    1. if(Physics.Raycast (shootRay, out shootHit, range, shootableMask))
    2.         {
    3.          
    4.  
    5.             //Rigidbody bulletforce = shootHit.collider.GetComponent <Rigidbody> ();
    6.          
    7.                 //if (shootHit.transform.tag == "Cube")
    8.                 //if(bulletforce!=null)
    9.  
    10.             {
    11.                 //if (shootHit.transform.tag == "Boxes")
    12.                 (shootHit.rigidbody.AddForceAtPosition(transform.forward * 5,shootHit.point);
    Also tried with an "public Transform throwProjectile;"

    I tried different layers such as "Default,shooatble", tried different colliders.

    I would love to know how to do this!