Hello there!
I am using C# to code my scripts and I want a way so that when you click somewhere on the camera view that your character will translate to that mouse click coordinates.
I have a general idea, however can’t finish it.
Hello there!
I am using C# to code my scripts and I want a way so that when you click somewhere on the camera view that your character will translate to that mouse click coordinates.
I have a general idea, however can’t finish it.
Use the raycast like this:
public class ExampleClass : MonoBehaviour {
void Update() {
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, 100)) {
// Move your player as you wish:
YourPlayerToMove.position = hit.point;
}
}
}
Please, show us your approach (since you say you have a general idea) so we can help you implement it. It may be an even better idea to post the code you have tried (even if you failed, someone will tell you why your code doesn't work).
– Andres-FernandezWell that's even more than less than unhelpful. What's the problem? Where are you stuck?
– Downstream