Home Unreal Engine

Spawning projectile at alternating sockets?

PocketMonkey
polycounter lvl 4
Offline / Send Message
PocketMonkey polycounter lvl 4
Hello, I'm currently working on creating X-Wing Fighter mechanics (like in Rogue Squadron) in UE4. I have four sockets for each gun, but when firing, all four are obviously spawning the projectile. How can I spawn the projectile at the first socket, then the second, then third, fourth and then the first again?

Also right now it only shoots once when I press the left mouse button, how can I create continous input? Do I have to use the axis mapping for that?

Thanks in advance!

Replies

  • Vailias
    Offline / Send Message
    Vailias polycounter lvl 18
    First issue: Shooting only once.
    You're using a "Pressed" type of event rather than a "Down" type of event.
    Inputs typically have 3 events. Pressed, Down, and Released. Pressed and Released fire only once, when the button is pressed or released respectively. Down continues to return true so long as the button is held.

    Second issue: firing sequentially.
    You're using a for each loop, so what the code is doing it getting all sockets in the array each time the action event fires, and doing the spawn event for each.
    Ref: https://answers.unrealengine.com/questions/129319/foreach-doesnt-stop-executing-on-return.html

    it appears the node version of that loop doesn't break between ticks. So what you'll want to do is construct your own iterator and update the index of the socket each run through the loop, switching back to zero when you hit the top index.

    So something like the following, but in nodes.
    int NextIndex = 0;
    int NumberOfSockets = getAllSockets().length;
    
    onFireButtonDown()
    {
    if(canFire)
    {
     fire(nextIndex);//do the spawning and other fun stuff here
    
    NextIndex += 1;
    NextIndex %= NumberOfSockets;
    canfire = false;
    }
    }
    delaynode //like you have to set fire back to true
    

    This should get the fire event to run through all the code once each tick until your firing time is back up.
  • PocketMonkey
    Offline / Send Message
    PocketMonkey polycounter lvl 4
    Thank you, I will try it out once I have time!
Sign In or Register to comment.