Hey,
So for school I have to make a 2D platformer and I thought of this game where you teleporting is key, but I want to prevent teleporting through walls.
Vector3 mousePos = Camera.main.ScreenToWorldPoint (Input.mousePosition);
Debug.DrawLine(player.position, new Vector3(mousePos.x, mousePos.y, player.position.z));
if (Input.GetMouseButtonDown (0)) {
RaycastHit2D rayCast = Physics2D.Raycast(mousePos, Vector2.zero);
if(rayCast.collider == null) {
player.position = new Vector3(mousePos.x,mousePos.y,player.position.z);
} else {
Debug.Log ("Struck something at: " + rayCast.collider.gameObject.transform.position);
}
//Debug.Log("Position " + mousePos);
}
This detects if I click on something. However I also want it to detect anything in between my player and the position of the mouse.
Greetings, Ferdi