• Visit Rebornbuddy
  • [CR] Cast Spell at Position; Calculating Position

    Discussion in 'Archives' started by randomstraw, Feb 6, 2014.

    1. randomstraw

      randomstraw Community Developer

      Joined:
      Jul 17, 2012
      Messages:
      1,611
      Likes Received:
      10
      Trophy Points:
      38
      Lets say i am a Spectral Thrower, and i want to always aim at the position furthest away, to keep the spread of my Spectrals at a minimum, essentially shotgunning near mobs.

      the black dot is me, the red dots are enemies, the ourter circle is my projectile range - the purple ones (i guess it was purple, maybe its blue, dunno) are the desired positions to cast my spell at, using the pressShift = true.

      my mind is currently around different stuff, has anyone an idea how to start this? ;)


      [​IMG]
       
    2. tozededao

      tozededao Community Developer

      Joined:
      Jan 15, 2010
      Messages:
      1,225
      Likes Received:
      5
      Trophy Points:
      38
      This!

      My idea would be:

      After you now your Spectral Throw Range, wether by calculating it or just a plain variable, lets say it is 40 yards.

      Maybe using vectors who are based on distance and angle, if a monster is at 20? degrees direction you would always cast at 20? degrees and 40 yards distance even though the monster was in a closer distance.

      Basically you would be interested only on the angle and not the actual distance of the monster since the distance will be always your max Spectral Throw distance. Obviously you still had to do some handling since sometimes that position is not clickable.
       
    3. Apoc

      Apoc Moderator Staff Member Moderator

      Joined:
      Jan 16, 2010
      Messages:
      2,790
      Likes Received:
      94
      Trophy Points:
      48
      You can do this easily actually, but you'll need to check for input errors caused by clicking "off screen"

      Sorry, this is in 3D (as I'm working on something related to it), but this is easily changed to 2D.

      Code:
              public Vector3 GetPositionFacing(Vector3 start, Vector3 target, float distance)        {
                  var dir = target - start;
                  dir.Normalize();
      
      
                  return start + (dir * distance);
              }
       

    Share This Page