HeroEngine Forums
Welcome, Guest. Please login or Register for HeroCloud Account.

Author Topic: weird results with distance formula  (Read 691 times)

Thazager

  • General Accounts
  • *
  • Posts: 1155
  • Never stop learning
    • View Profile
    • Heroes and Villains MMORPG
weird results with distance formula
« on: Jul 26, 13, 09:58:26 PM »

I can run up to the monkeytok and attack and kill it. Nothing wrong there. I can pull the monkeytok with fireball and it runs to attack me. Nothing wrong there. When I attack with weapon after pulling the monkeytok to me with fireball, it says "Target is too far." What I am noticing is that, the printed value of range is not based on the positions of the player and the monkeytok, but rather the player and the spawn position of the monkeytok.

In the wiki I found this:

Obtain the length of a vector

This function returns the square root of x*x + y*y + z*z, which is the length of a vector
function VectorLength( v as vector3) as float
Note: this is the function that you use to get the distance between two points.

point1 as Vector3 = vc.character_position
point2 as Vector3 = targVC.character_position
dist as float = VectorLength(point1 - point2)


In E_abilityClassMethods in method CanActivateAbility() the formula is used. Where targetCharacter as NodeRef of Class E_CommonCharacter, and owner as NodeRef of Class E_CommonCharacter. I added a printout of range underneath the var range =. When the monkeytok runs to me, I get high numbers for range. When I run to the monkeytok, I get low values. When I stand where the monkeytok spawned, I get 0.

Code: [Select]
      $CHAT.ChatArea( "", "range=" + range )

Code: [Select]
      // calculate range     
      var targetPos = targetCharacter.GetMyVisibleCharacter().character_position
      var ownerPos = owner.GetMyVisibleCharacter().character_position
      var range = VectorLength( targetPos - ownerPos )
     
      // check min range
      if( range < me.E_script:GetMinRange() )
        return ResultUtils:ErrorWithMessage( "Target is too close." )
      .
     
      // check max range
      if( range > me.E_script:GetMaxRange() )
        return ResultUtils:ErrorWithMessage( "Target is too far." )
      .
Logged