Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. 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!