Search Unity

Help with script to calculate force needed for projectile to reach target in 2D

Discussion in 'Physics' started by marciotf, Jan 7, 2019.

  1. marciotf

    marciotf

    Joined:
    Jul 15, 2016
    Posts:
    15
    Hi,
    Does anyone have a script to calculate the force necessary for a projectile to reach a certain point based on a specific launch angle, something like a mortar? For a 2D project, dealing only with x and y coordinates.

    The info I have is the local projectile position, the target position, and the launch angle. I need a script to calculate the force needed to be applied in the projectile, via GetComponent<Rigidbody2D>().AddForce(new Vector2(x, y), ForceMode2D.Impulse);.

    I have spent the last hours reading posts and tried several scripts and cannot get it to work.

    If someone has a example script for 2D it would really help me.

    Thx,
     
  2. marciotf

    marciotf

    Joined:
    Jul 15, 2016
    Posts:
    15