Search Unity

Adding force to and object

Discussion in 'Scripting' started by 3B00DG4MER, Aug 4, 2015.

  1. 3B00DG4MER

    3B00DG4MER

    Joined:
    Jun 24, 2015
    Posts:
    64
    Hi guys,
    I've created a weapon system
    So i wanted to make it if the bullet hit a colider and the rigidbody of that colider
    add force as the bullet damage, same forward as the bullet
    but i've problem, when i add force to object it's goes randomly, and not as same as the bullet forward
    here's the video that explains :
    https://vid.me/BDbK
    and thanks for help :D
     
  2. 3B00DG4MER

    3B00DG4MER

    Joined:
    Jun 24, 2015
    Posts:
    64
  3. phoda

    phoda

    Joined:
    Nov 11, 2014
    Posts:
    384
    you can take the forward rotation of bullet and apply force on object based of bullets forward. in on collision function just pass (transform.forward if iam not mistaken) and use it as direction of force
     
  4. 3B00DG4MER

    3B00DG4MER

    Joined:
    Jun 24, 2015
    Posts:
    64
    if i use this, look what's happens in the video
     
  5. DonLoquacious

    DonLoquacious

    Joined:
    Feb 24, 2013
    Posts:
    1,667
    The video shows the result, but explains nothing. You need to post the code that you've used to reach this result.

    Basically though, you need to use the bullet's transform.forward (you can multiply this by speed and weight of the bullet, if you like) and ForceMode.Impulse (instant impact force, not continuous).
     
    Last edited: Aug 5, 2015
  6. 3B00DG4MER

    3B00DG4MER

    Joined:
    Jun 24, 2015
    Posts:
    64
    Ow, changing ForceMode to Impulse did the trick
    Thanks :D