- Home /
Question by
Stradigos · Dec 16, 2014 at 03:32 AM ·
raycastcollidertransformraycasting
Fixing Editor Mouse Offset Due To Local Raycast?
It's not exactly game breaking, but the fact my local raycast makes my in-editor mouse offset now is a bit annoying. Can anything be done about this?
In other words, the mouse pointer was where the green arrow is shown in the pic. That was before the InverseTransformPoint business. Now my mouse pointer is where it's shown in the pic. Of course the mouse pointer didn't move, it's just targeting differently.
// Update is called once per frame
void Update() {
// Cast ray
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hitInfo;
// Cursor on map
if (gridManager.GridCollider.Raycast(ray, out hitInfo, Mathf.Infinity))
{
// Get relative point
Vector3 relative = gridManager.GridTransform.InverseTransformPoint(hitInfo.point);
// Get tile coordinate
int coordX = Mathf.FloorToInt(relative.x / gridManager.GridTileSize);
int coordZ = Mathf.FloorToInt(relative.z / gridManager.GridTileSize);
currentTileCoord.Set(coordX, 0.01f, coordZ);
Comment
You should close the question then... It's good for UA cleanup ;)
Best Answer
Answer by EvilTak · Dec 16, 2014 at 06:18 AM
Instead of using Collider.Raycast use Physics.Raycast.