Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

AIMER

Discussion in 'Scripting' started by MetroidHunter, Jun 25, 2007.

  1. MetroidHunter

    MetroidHunter

    Joined:
    May 22, 2007
    Posts:
    213
    how could i make an aimer that would move to Enemy tags on shreen one at a time and make my gun point at it. :x
     
  2. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    The GameObject class has a method called FindGameObjectsWithTag. You could call this from your gun script to find all the objects tagged as enemies. You would, of course, have to visit the elements in the array in the most appropriate order for the game (target most dangerous enemies first, say).

    You can get the direction from the gun to the enemy object by subtracting the gun's transform.position vector from the enemy's. Then, you can make the gun object point at the enemy using Quaternion.LookRotation, passing the direction you got with the vector arithmetic.

    You can move smoothly between the gun's current direction and the direction to the enemy by using Quaternion.Slerp on the two directions.
     
  3. AaronC

    AaronC

    Joined:
    Mar 6, 2006
    Posts:
    3,553
    search the forum for VehicleExamples. Its an unofficial otee demo with what you seek...
    AC