Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question A movement that slightly curves behind the shooter for a bit then goes toward the target

Discussion in 'Scripting' started by billygamesinc, Nov 29, 2023.

  1. billygamesinc

    billygamesinc

    Joined:
    Dec 5, 2020
    Posts:
    288
    upload_2023-11-29_13-7-4.png
    I was wondering how I could approach making a projectile move in a way that moves behind the origin for a bit that ramps up in speed and moves toward the target. Heres an example of an enemy that does something like this with its needle attack. @:0:49
     
    Last edited: Nov 29, 2023
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,846
    Just shoot the projectiles out with the specified original velocities for that pattern, and over time have them seek towards the target in a typical "homing missile" fashion. You can add a delay before the homing behavior starts as well if you want.
     
    Kurt-Dekker likes this.
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,329
    Yes! What @PraetorBlue says... see my handy attached Missile Turn Towards packages if you want a start on the whole "turn towards" mechanic.

    There's two examples, one for 2D and one for 3D... go nuts!!
     

    Attached Files:

    billygamesinc likes this.
  4. zulo3d

    zulo3d

    Joined:
    Feb 18, 2023
    Posts:
    767
    A simple way to look at this is that it's basically the same as what we do with gravity and jumping characters. We apply a constant force downwards and apply a brief upwards force to our characters to make them jump and the gravity then pushes them back down to the ground. And if we make the character run at the same time as it jumps then it moves along a curve.

    So spawn a projectile at the back of the blue circle and apply a "jump" force in the negative blue.transform.forward axis with some up force mixed in and then apply a constant force to the projectile in the direction of the red circle.
     
  5. billygamesinc

    billygamesinc

    Joined:
    Dec 5, 2020
    Posts:
    288
    That seems simple enough thank you!