- Home /
How to get the ground position near the gameObject clicked?
Hello.
I have the Player prefab, which have some movement controls, in the RTS Style. Something really close the diablo 3. The mobs prefabs are clickable. So, when the player click the mob, it "starts" the attack. The Player has the "attackRange" to define the distance which the player are able to hit the mob. When the player is too far away from the mob (distante > attackRange), the player needs to get closer to the mob, and thats been my difficult. Here is what im doing. Any help would be appreciate!
Sorry for bad english.
void DefineOponent(Vector3 click)
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay (click);
if (Physics.Raycast (ray, out hit, 1000))
{
if(hit.collider.tag == "Mob")
{
Oponent = hit.collider.gameObject;
if (Physics.Raycast (ray, out hit, 1000))
{
posicaoDestino = new Vector3 (hit.point.x, hit.point.y, hit.point.z);
}
}
}
}
then, i do the move:
CharacterController jogController = this.GetComponent<CharacterController>();
this.transform.LookAt(Oponent.transform);
jogController.SimpleMove(6 * this.transform.forward);
Your answer
Follow this Question
Related Questions
What's Wrong With This Script? 1 Answer
RTS Minimap Movement 0 Answers
Follow mouse until mouseclick 0 Answers
Camera rotation around player while following. 6 Answers
Click-and-Move System: Unit flies upward on slopes 0 Answers