Hi guys, firstable, I already created a button for fire and it works, okay but I want to do when I click to “button”, my characters fire automatically to enemies bodies. ( Im working on Android project )
I can’t find how to do it, I was search all forums but I can’t find.
Hi man,
Its some work to do!
your “Gunner” should know the enemies position , and number , and distance…
So , use get all actor of class, or something like that to find all them, save them in a array. (Search for Get all actors of class)
Now if you want you can checck if they are visible,
Use a raycast from Gunner location to Enemies location, you can do it in a loop of the enemies array (search for loop and raycast by visibility).
If the raycast find an obstacle, you delete that enemy from the array, (Search for Deleting from array)
Then you can check the distance and rearrange the array for it (rearange the array)
Now that you know who is your target, the closest one i think.
You have to rotate the Gunner toward the Target (search for" look at" node)
And now he should shoot endlessly? or until ammo run out?
By the way, make your custom event and use it to : (Search Custom event)
Constatly rotate toward the array_enemy_n1, and shoot, delay 0.5 sec and recall the custom event
Be sure to add a variable to stop the cycle , or use a gate to do it (Search for gates)
Check if the enemy n1, the closest is alive, if no, delete him in the array,
If the array is empy, do nothing ,and stop shooting XD
You have to add a way to make your guunner Check again for enemies
when they spawn or are close, or the game start…
Thank you for help man, but actually my character is gunner
So this is what I mean;
Do you know Alien Shooter for android mobile game? A.S. shooting system is my dream. So yeah, thanks for help, I’m gonna try to ur advice.
Do you mean continuous fire, I mean, to keep firing while button is pressed?
Hey man, thanks!
When I press the button, I want the action of firing to be directed towards the enemy body. I have tried many methods, a method that I have right now;
I can’t find where I made a mistake. In addition, I want the bullet to not affect my character when it touches my character. Because I die when my bullet touches myself.
Do you want the shooter to rotate towards the target or, the projectile to go towards the target regardless of the shooter orientation?
Who is the shooter? FPS or TPS or some sort of turret?
What is happening now?
You either spawn the bullet further from the character or do some check (a cast or tag verification) or use an interface when the bullet hits something. For example:
](filedata/fetch?id=1787617&d=1594665334)my character is a TopdowngameCharacter and my game is similiar like Alien Shooter. but I’m trying to do this for the mobile platform. When the button is pressed as in the image, my character should turn to the enemy and shoot automatically. I will try the idea that you presented so that my character is not affected by the bullet. I’m drop this so you can imagine;
Here is a solution. When you press shoot (X in my case), the player will instantly rotate towards the target or enemy, and shoot:
](filedata/fetch?id=1787654&d=1594668575)Your problem was most likely in the usage of the character’s rotation instead of the controller. I say, most likely, because I have no idea how you are controlling your character. I don’t know, if your inputs are setting the control rotation (perhaps using Add Controller Yaw Input) or not.
In relation to the bullet, you should spawn it from a socket or from some other reference, located in the muzzle of the gun. This would avoid having to check if you hitted yourself. Right now, you are spawning right from the center of your character.
I did it but bullet is going right always. Really I can’t handle it…
But does the player rotates towards the target?
Edit: what do you mean “is going right always”? Right in relation to what? In local or world space?
I need to know how you’re controlling the character.