I have what i think is correct for teleporting a player to a mouse position.
I can ray cast fine and turn and face the direction i want to teleport but i can’t seem to get my head round the last part by teleporting to the location of the mouse.
seems to teleport back to 0,0,0 cords will keep researching to see if i can get it but thanks in advance.
if (Input.GetKeyDown ("f")) {
Debug.Log ("flash key pressed" + Time.time);
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast (ray, out hit)) {
Vector3 mousePos = hit.point;
Debug.Log ("x.pos" + mousePos.x);
Debug.Log ("y.pos" + mousePos.y);
Debug.Log ("z.pos" + mousePos.z);
transform.LookAt (mousePos, Vector3.forward);
transform.position = new Vector3(mousePos.x, mousePos.y, mousePos.z);
}
transform.position = transform.forward;
}
//transform.position = new Vector3(mousePos.x, mousePos.y, mousePos.z);
// Simpler to write:
transform.position = mousePos;
// You were overwriting the mouse position with this for some reason?
//transform.position = transform.forward;
I have worked out a way to do it but its a little robust, i disabled the navmeshagent which did the trick but I’m sure there is a smoother way of doing this?