Hello.
I have a problem when shooting: I am doing types of shots (like a shotgun and similar) but two do not work for me:
Burst Shot: What it does is it creates all the bullets at the same time, making the bullets not separated.
else if(tipoDisparo_SD == "2A")
{
if(cadencia_SD <= 0)
{
int i = requisito_SD;
while(i != 0){
DispararRafaga();
cadencia_SD = 0;
i--;
}
cadencia_SD = CADENCIA;
}
else
{
cadencia_SD -= Time.deltaTime;
}
}
private void DispararRafaga(){
Instantiate(bala_SD[0], pos.position, pos.rotation);
QuitarBalas(requisito_SD);
Debug.Log("Dispara");
}
Bullet hell shot: creates all the bullets but fires them in the same position ignoring what is shown in the debug.log. In this it shows that it does the operation correctly.
case "4A":
div = 360 / requisito_SD;
rotacion = jugadorGirador.rotation;
res = div;
Debug.Log("Grados: " + res);
for(int i = 1; i <= requisito_SD; i++){
rotacion.z += res;
Instantiate(bala_SD[0], pos.position, rotacion);
Debug.Log("Rotacion: " + rotacion.z + " de: " + i);
Debug.Log("ROT: " + rotacion);
}
break;
What will be the problem?
Gabo19x:
Hello.
I have a problem when shooting: I am doing types of shots (like a shotgun and similar) but two do not work for me:
Burst Shot: What it does is it creates all the bullets at the same time, making the bullets not separated.
else if(tipoDisparo_SD == "2A")
{
if(cadencia_SD <= 0)
{
int i = requisito_SD;
while(i != 0){
DispararRafaga();
cadencia_SD = 0;
i--;
}
cadencia_SD = CADENCIA;
}
else
{
cadencia_SD -= Time.deltaTime;
}
}
private void DispararRafaga(){
Instantiate(bala_SD[0], pos.position, pos.rotation);
QuitarBalas(requisito_SD);
Debug.Log("Dispara");
}
Bullet hell shot: creates all the bullets but fires them in the same position ignoring what is shown in the debug.log. In this it shows that it does the operation correctly.
case "4A":
div = 360 / requisito_SD;
rotacion = jugadorGirador.rotation;
res = div;
Debug.Log("Grados: " + res);
for(int i = 1; i <= requisito_SD; i++){
rotacion.z += res;
Instantiate(bala_SD[0], pos.position, rotacion);
Debug.Log("Rotacion: " + rotacion.z + " de: " + i);
Debug.Log("ROT: " + rotacion);
}
break;
What will be the problem?
Hi Raxwe , thanks for the info. I am not sure I understand fully. I wonder are you able to provide some image or video on the issue you are facing?
In the image you can see 5 arrows, which is where the 5 bullets are supposed to go in that direction. But all 5 bullets come out the same side (orange dots). You can also see that the 5 bullets are created correctly. there is also a Debug.log that shows that it seems to do the correct operation. But the execution is wrong.
Gabo19x:
rotacion.z
This is NOT what you think it is. It has absolutely NOTHING to do with degrees. This is an internal component of Quaternions, which have internal x, y, z, and w components.
Do NOT touch ANY of those components unless you have a math degree and know what youâre doing.
Instead, either use the Quaternion.Euler() factory method to make each of your rotations, or else use a pre-made constant one (such as Quaternion.Euler(0,0,res)
) and multiply the rotacion
variable by it each time to make it âspreadâ
1 Like
I am close to achieving it, but there is a bullet that does not come out correctly, and the appearance of the bullets is fixed, I show you the script:
case "4A":
div = 360 / requisito_SD;
rotacion = jugadorGirador.rotation;
res = div;
Debug.Log("Grados: " + res);
for(int i = 1; i <= requisito_SD; i++){
res += res;
rotacion = Quaternion.Euler(0, 0, res);
Instantiate(bala_SD[0], pos.position, rotacion);
Debug.Log("Rot: " + rotacion.z + " de " + i);
}
break;
To combine I only need to multiply them⌠But there is still a bullet that is not created where it is⌠(I think it is when it is 0)
case "4A":
div = 360 / requisito_SD;
rotacion = jugadorGirador.rotation;
res = div;
Debug.Log("Grados: " + res);
for(int i = 1; i <= requisito_SD; i++){
res += res;
var rot = Quaternion.Euler(0, 0, res);
rotacion = rotacion * rot;
Instantiate(bala_SD[0], pos.position, rotacion);
Debug.Log("Rot: " + rotacion.z + " de " + i);
}
break;
One build fails when ârequisito_SD = 5â but setting ârequisito_SD = 9â fails three. What can I do?
Gabo19x:
res += res;
This doesnât seem right. It is the equivalent of res *= 2;
Do you mean res += div;
perhaps?
Again, you should remove this:
rotacion.z
is meaningless. Stop letting it confuse you.
I fixed it. Line 9 is left over. Since I added the multiplication, I was âaddingâ more times than I should have.
case "4A":
div = 360 / requisito_SD;
rotacion = jugadorGirador.rotation;
res = div;
Debug.Log("Grados: " + res);
for(int i = 1; i <= requisito_SD; i++)
{
// res += res; -> needless
var rot = Quaternion.Euler(0, 0, res);
rotacion = rotacion * rot;
Instantiate(bala_SD[0], pos.position, rotacion);
Debug.Log("Rot: " + rotacion.z + " de " + i);
}
QuitarBalas(requisito_SD);
break;
Now it is necessary to improve the burst style shot (create all the bullets at the same time without separation)
case "2A":
for(int i = 1; i <= requisito_SD; i++)
{
Invoke("DispararRafaga", 2f);
}
private void DispararRafaga(){
Instantiate(bala_SD[0], pos.position, pos.rotation);
QuitarBalas(requisito_SD);
Debug.Log("Dispara");
}
Gabo19x:
I fixed it. Line 9 is left over. Since I added the multiplication, I was âaddingâ more times than I should have.
case "4A":
div = 360 / requisito_SD;
rotacion = jugadorGirador.rotation;
res = div;
Debug.Log("Grados: " + res);
for(int i = 1; i <= requisito_SD; i++)
{
// res += res; -> needless
var rot = Quaternion.Euler(0, 0, res);
rotacion = rotacion * rot;
Instantiate(bala_SD[0], pos.position, rotacion);
Debug.Log("Rot: " + rotacion.z + " de " + i);
}
QuitarBalas(requisito_SD);
break;
Now it is necessary to improve the burst style shot (create all the bullets at the same time without separation)
case "2A":
for(int i = 1; i <= requisito_SD; i++)
{
Invoke("DispararRafaga", 2f);
}
private void DispararRafaga(){
Instantiate(bala_SD[0], pos.position, pos.rotation);
QuitarBalas(requisito_SD);
Debug.Log("Dispara");
}
Hi Raxwe , great that you have found the solution.
When shooting in burst mode no. the others are functional
Hi Raxwe , do you have a image or video sample that you would like to achieve in your burst mode?
Gabo19x:
Now it is necessary to improve the burst style shot (create all the bullets at the same time without separation)
private void DispararRafaga(){
Instantiate(bala_SD[0], pos.position, pos.rotation);
QuitarBalas(requisito_SD);
Debug.Log("Dispara");
}
Hi Raxwe, same here you need to pass in the Quaternion.Euler() to into your Instantiate(gameObject, position, Quaternion)
var angle = 40 // example 40 degree angle
var rotation = Quaternion.Euler(0, 0, angle);
Instantiate(bala_SD[0], pos.position, rotation);