# Cursor and mouse position alignment

**URL:** <https://discourse.processing.org/t/cursor-and-mouse-position-alignment/29116>\
**Category:** Processing\
**Created:** [April 4, 2021, 5:50pm UTC](https://discourse.processing.org/t/cursor-and-mouse-position-alignment/29116 "2021-04-04T17:50:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Criste44](https://avatars.discourse-cdn.com/v4/letter/c/a8b319/32.png) [@Criste44](https://discourse.processing.org/u/Criste44)\
**Post date:** [April 4, 2021, 5:50pm UTC](https://discourse.processing.org/t/cursor-and-mouse-position-alignment/29116/1 "2021-04-04T17:50:07Z")

</div>

> please format code with \</\> button \* [homework policy](https://discourse.processing.org/faq/#homework) \* [asking questions](https://discourse.processing.org/t/2147)

I am trying to highlight tiles, that are hovered by the mouse. This is my code:

```
void Update ()
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
    Vector3 point = hit.point;
    Vector2Int gridPoint = Geometry.GridFromPoint(point);

    tileHighlight.SetActive(true);
    tileHighlight.transform.position = Geometry.PointFromGrid(gridPoint);
    if (Input.GetMouseButtonDown(0))
    {
      // ... 

```

Edit:

```
 public class Geometry
 {  
 static public Vector3 
  PointFromGrid(Vector2Int gridPoint)
{
    float x = -3.5f + 1.0f * gridPoint.x;
    float z = -3.5f + 1.0f * gridPoint.y;
    return new Vector3(x, 0, z);
}

static public Vector2Int GridPoint(int col, int row)
{
    return new Vector2Int(col, row);
}

static public Vector2Int GridFromPoint(Vector3 point)
{
    int col = Mathf.FloorToInt(4.0f + point.x);
    int row = Mathf.FloorToInt(4.0f + point.z);
    return new Vector2Int(col, row);
}

```

}  
The cursor object is not under the mouse how can I fix and align it?

 ![Screenshot_20210404-164707_Fotoğraflar~2](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/7/72a80ed070563d2a175e6a54a27793d13fcca352.jpeg) ![Screenshot_20210404-165159_Fotoğraflar](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/f/fd4af7ff83af41cdc73c78df5f486295fe1fb3ef.jpeg) ![Screenshot_20210404-164640_Fotoğraflar](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/1/177c6fe75a48557c2da9ed228e8dd1737974c6a2.jpeg)

---

<div class="post-metadata">

**Author:** ![micuat](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micuat/32/19407_2.png) [@micuat](https://discourse.processing.org/u/micuat)\
**Post date:** [April 6, 2021, 9:43pm UTC](https://discourse.processing.org/t/cursor-and-mouse-position-alignment/29116/2 "2021-04-06T21:43:34Z")

</div>

I just noticed that this looks like C#/Unity 🤯 I’m very sorry but this forum is for Processing / p5.js so I recommend you to ask on [Unity forum](https://forum.unity.com/).
