Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Help needed to create a 2d sprite gun which follows and shoots the enemy

Discussion in '2D' started by conroar94, Nov 25, 2015.

  1. conroar94

    conroar94

    Joined:
    Nov 22, 2015
    Posts:
    3
    I am a very begginer with unity. i have created several sprites for each angle for the gun to shoot from, i was just wondering how do i get each image to appear at a certain range of the sprite to look like the gun is moving to shoot the enemy?

    sorry if it isnt phrased very well.

    someone has mentioned direction and distance from one object to another but i have no idea how to do this either :S sorry im such a noob
     
  2. Sheikz

    Sheikz

    Joined:
    Nov 1, 2015
    Posts:
    24
    To get the distance between two objects "gun" and "enemy" you can do:

    Code (csharp):
    1. float distance = (gun.transform.position - enemy.transform.position).magnitude;
     
    conroar94 likes this.
  3. conroar94

    conroar94

    Joined:
    Nov 22, 2015
    Posts:
    3
    thank you so much <3!