- Home /
Question by
rodrigodebem7 · Dec 03, 2019 at 02:59 PM ·
c#visual studiorpg
Projectile Rotation
Hi guys,
I'm making a turn based RPG and I'd like to know how could I use the function Lookat to instantiate the bullet in the opponent's direction? Because in the way that I've programmed, the projectile just goes in a straight line.
I'm using this function to shoot:
public void TeslaShooting()//Tesla's shooting method
{
for (int i = 0; i < Personagens.Length; i++)
{
if (Personagens[i].tag == "Tesla" && Input.GetMouseButtonDown(1)
&& Personagens[i].GetComponent<Jogador>() &&
Personagens[i].GetComponent<Jogador>().PodeAtacar == false
&& Personagens[i].GetComponent<Jogador>().isPlayer)
{
//raycast checks and returns an object, if it's a tile, the unit shoots
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
if (hit.transform.tag == "Espantalho"
|| hit.transform.tag=="Xama"||hit.transform.tag=="Sheriff")
{
//instantiates the bullet
GameObject tiro = Instantiate(projetil, SpawBala.transform.position,SpawBala.transform.rotation);
Rigidbody BalaRigid = tiro.GetComponent<Rigidbody>();
BalaRigid.velocity = SpawBala.transform.forward * ProjetilVeloc * Time.deltaTime;
gameManager.PontoAcaop1--;
Personagens[i].GetComponent<Jogador>().PodeAtacar = true;
interfaceManager.ActionPointDown();
}
}
}
}
}
If the opponent is in my side or in a diagonal positon I cannot hit him.
How could I solve it guys?
Comment
Your answer
Follow this Question
Related Questions
Methods are executed at the same time 0 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
NPC Movement in a Tactical RPG Game 0 Answers
RPGStatSystem tutorial problem with clases visibility? 1 Answer