Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Move towards an object but using physics

Discussion in 'Scripting' started by Duskman0, Jul 31, 2020.

  1. Duskman0

    Duskman0

    Joined:
    Apr 28, 2019
    Posts:
    3
    I'm working on a 2D sidescroller in 3D Unity with physics based movement but I'd like to implement a feature where you can fling yourself directly at an enemy by clicking on them. I figure I could achieve this with something like Vector3.movetowards but that would be non physics based movement.

    Basically how can I get the player to move to mouse position but using physics? They don't need to stop once they hit the mouse position, but they do need to hit exactly where mouse position is. Sorry I hope this makes sense, please let me know if you need any more info.
     
  2. WarmedxMints

    WarmedxMints

    Joined:
    Feb 6, 2017
    Posts:
    1,008
    You calculate the direction as a vector from the player to the point, the force required for the player to reach the target point, and add force in that direction.
     
    Joe-Censored likes this.
  3. Duskman0

    Duskman0

    Joined:
    Apr 28, 2019
    Posts:
    3
    How would I go about calculating the force required for the player to reach the target?
     
unityunity