Aller au contenu

Photo

Simple math problem - finding the center of a tile


  • Veuillez vous connecter pour répondre
4 réponses à ce sujet

#1
3RavensMore

3RavensMore
  • Members
  • 703 messages

My math brain is completely out to lunch today.  I need a function that will calculate the tile center from the x,y position of a waypoint. 

 

Edit: I have it now:

FloatToInt((vPosition.x) / 10) * 10 + 5;



#2
KMdS!

KMdS!
  • Members
  • 189 messages

....you got it



#3
KMdS!

KMdS!
  • Members
  • 189 messages

Here is something you can look at, not sure it's what you were looking for , but there might be something there for you. I was working on it and finished before I saw you got what you needed.

// Will return the center of the specific tileset tile the OWaypoint object is located
vector TileCenter(object oWaypoint)
{
    vector vWaypoint = GetPosition(oWaypoint);
    float fX,fY;
 
    float fX = vWaypoint.x;
    float  fY= vWaypoint.y;
 
    // Store the decimal value if fX
    float fX1 = fX-FloatToInt(fX);
    // Get the value of the ones column of fX
    int iX1 = FloatToInt(fX)%10;
    // The x coordinate within the specific tile
    float fX2 = fX1+iX1;
    // The x value for the distance to the center of the specific tile from the oWaypoint object
    float fX3 = (((10.0-fX2)-fX2)/2)+fX2;
    // The x value for center of the tile the oWaypoint object is located within the global environment
    float fX4= fX-fX2+fX3;
 
 
    // Store the decimal value if fY
    float fY1 = fY-FloatToInt(fY);
    // Get the value of the ones column of fY
    int iY1 = FloatToInt(fY)%10;
    // The y coordinate within the specific tile
    float fY2 = fY1+iY1;
    // The y value for the distance to the center of the specific tile from the oWaypoint object
    float fY3 = (((10.0-fY2)-fY2)/2)+fY2;
    // The y value for center of the tile the oWaypoint object is located within the global environment
    float fY4= fY-fY2+fY3;
 
    return Vector(fX4, fY4, 0.0);
}

  • Tarot Redhand aime ceci

#4
Tarot Redhand

Tarot Redhand
  • Members
  • 2 669 messages

That might be useful enough to post on the vault for anyone who needs such a script after this thread has disappeared 2 or 3 pages down the line.

 

TR


  • Grani aime ceci

#5
KMdS!

KMdS!
  • Members
  • 189 messages

Hmmm... I might just do that. Thanks.