- Home /
The question is answered, right answer was accepted
Converting C# Controller from WASD Controls to Click-Based
Hi everyone, I'm trying to convert the C# Character Controller scripts to mouse click based. But I'm not sure how. How do you detect the mouse click and where it clicks? Then from there it's just a simple transform.translate right?
Answer by Prodigga · May 29, 2013 at 12:43 AM
You can do a raycast down onto your terrain from the screen click location. Then I suppose you can move towards this point at some speed using Vector3.MoveTowards. If you need collision avoidance, you can eventually look at using navmesh's to move your character to the point you clicked.
the raycast code is pretty simple. What I like to do is put the terrain in its own layer and only raycast against that object
var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
var hit : RaycastHit;
if (Physics.Raycast(ray, hit, 100)) {
//hit.point will contain position to move to
//store this somewhere and move towards it
}
Follow this Question
Related Questions
C# Need Help converting from Rigidbody to Character Controller 0 Answers
C# FP_Camera not following Character Controller 0 Answers
C# CharacterController.SimpleMove Goes on Forever 1 Answer
C# Character Controller Collision If Statement 2 Answers
C# How to Access Character Controller's Properties without Declaring a Character Controller 1 Answer