[SOLVED] Trying to make my player shoot in opposite directions

In my practise twin stick shooter I have a power up that lets you swap between shooting two guns that face forward to where you have one gun firing forward and a second firing backwards.

My problem is trying to get the rear gun to fire directly backwards.
When the guns are firing forward they are targeting a crosshair that’s on screen and is moved using the right stick on a controller.
So I tried making a second crosshair for the rear gun to aim at that would be invisible to the player. However I couldn’t find a way to invert the second crosshairs movement so that, for example, if the main crosshair moved right the second one would move left.
My second attempt was the have the rear target the original crosshair but alter the angle so that it would fire away from it. However, while I could get it to fire away from the crosshair, I couldn’t get it to fire directly behind the player despite trying a few angle combos. Also when the player rotates it doesn’t fully commit to that altered angle and sometimes ends up firing directly forward again.

So any suggests on how I can get either my previous attempts to work or a better solution would be appreciated. I’ll add a screen shot of my current set up, minus my attempts and with the section I’m focused on highlighted.

Are you centering the camera on the player, or is your player able to move around on the screen without the camera following? I also don’t see any events related to movement of the crosshairs, do they move with the cursor or another mechanism? Do they move with the player? This is important info you should always try to include in posts.

Are you centering the camera on the player, or is your player able to move around on the screen without the camera following? - As shown in the screen shot, the camera is not cantered on the player. They are able to freely move around the full screen without the camera following.

I also don’t see any events related to movement of the crosshairs, do they move with the cursor or another mechanism? - I am using the Top Down Gamepad Mapper from the Gamepads extension for the crosshair and is controlled using the right stick. I’ll add a screen shot.

Do they move with the player? - The player sprite is also using Top Down Gamepad Mapper and is controlled using the left stick.
As shown in the screen shot the player rotates based on the location of the crosshair to allow aiming in all directions.
Hope this has answered all your questions.

Thank you for the extra info, although I’m still a bit unsure of how the crosshair and player movement is supposed to be connected. Do the crosshairs move with the player eg. if the cross hair is pointing at 500, 600 and the player moves up 100 pixels will the crosshair be at 500, 500 or is the cross hair independent of player movement, and when the player moves up 100 pixels, the crosshair stays at 500, 600? Like this for example:

If you screen record a quick video (and convert to GIF) of the player and crosshair movement during runtime that would be mucho appreciated. Once I see a video of the mechanics I should be able to code up what you want pretty quickly.

If the player moves, the crosshair doesn’t move. It’s independent of the player movement.
Each are controlled separately, only thing to note is that no matter where the crosshair is the front of the player’s character is pointed at the crosshair.
As requested I’ve created a gif example.
Please excuse the amateur placement sprites. :laughing:
The front of the player is marked red with the little cannon. You’ll see at the end the front and rear cannon mode with the rear cannon firing forward.
movement example

Nice okay so the code I used for my GIF should work fine then (as basic as it is).

the 32 just stands for half the width of the crosshair and half the height of the crosshair respectively, just change it to match yours. And you can keep the same player rotation mechanics and what not. Just have the player rotate toward crosshair1. Btw if you really don’t want to use tween there are multiple ways to move the crosshair with the cursor (while still using the same math).

Thanks for your suggestion, but unfortunately it doesn’t appear to work for me.
I filled it in as you displayed it, though I couldn’t put anything in the “behaviour” section.
But when I previewed it the second crosshair still mirrored the original’s movement.

I figured it was because I was using (as shown in my previous screen shot) a gamepad to control the crosshair, so I swapped out for a cursor but the second crosshair didn’t move then.
I should note reason I’m using just a gamepad for controlling the crosshair is because having the cursor behaviour switched on at the same time prevented me from using the gamepad controls. So I’ve just stuck to using the joysticks on a gamepad for my twin stick shooter.

Have you tried just getting rid of the first tween event but keeping the second as is (still using crosshair2)?

Tried removing the first tween as you suggested but sadly still no luck, second crosshair still copies the first one’s movement.
second crosshair movement

Can you screenshot and post all the events.

With the exception three layers and animation event stuff at the bottom not being displayed, my first post’s screen shot was all my current events. Only edition I’ve added was your suggestions. But here is are a pair of screen shots showing everything together so you don’t have to scroll up and down between two posts :wink:

Hmm a thought just crossed my mind. Have you removed all topDownMovement behavior from the second crosshair? In fact the only behavior it should have should be tween.

I did try removing those movements in an earlier attempt but that didn’t work. However I didn’t notice the tween behaviour last time so added that to both crosshairs and now I have good news and odd news.
Good news, it’s now moving inverted to the original crosshair as desired.
Odd news, not only does it jump to the position you see in the start of the gif below when I preview it, but when I make the preview full screen it runs off screen.
good news odd news

Okay in that case use CameraHeight and width instead of ScreenHeight and width. This should temporarily fix the problem, let me know if it works for you.

I’ve now changed both ScreenHeight/Width to CameraHeight/Width.
ScreenWidth had it move to the right nearly going off screen, so I figured to change that to camera as well.
So it no longer flies off screen but instead just hops a little to the right.
Feels like we’re so close :laughing:
not fly off screen

I tried to alter crosshair2’s position but the most I’ve been able to do is change its starting position when I run the preview. So now if I play windowed it’s pretty much spot on what wanted it to do. However it still does its little hop to the right if I go full screen.

just a step to the right

I’ve also spotted another issue that’ll I need to figure out. That being keeping the second crosshair behind the player as they move. But one issue at a time :sweat_smile:
second crosshair does not follow

Good news, I managed to get my little submarine to shoot forwards and backwards. Turns out the answer was a lot more simple than I thought it was going to be.

Basically on my player sprite I crated a point at the rear of the sub and named it “RearFire”.

I then had the position the rear gun fired from target that point.
Got rear shooting working
So now I have my desired result, shooting in opposite directions!
Thank you for all your suggestions, I did learn a fear bit in our back and to trying to figure it out. :grinning:

Ah, that is a great solution!