How can I smooth out gun+player movement in my 2D platform shooter?

The flip of the gun and player in my game is a mess:
2
As you can see in the .gif, when it reaches a certain point the gun flips with the character, as I programmed it to do:


But it doesn’t looks right (the character is almost pointing it to himself).

I thought I could fix it by implementing a crosshair in the game, and set a no-go zone around the player so the cursor & crosshair collide with the player, unabling the game to let the player “aim at themselves”, which is something I don’t know how to to.

Which way would you say I can fix my issue?

This is the most accurate thread for angles problems…imo you need the clamp angle function…and the mouse clamp to distance if you dont want players to aim on character…but i dont see the problem there as long as angles works properly

test the zero build here

2 Likes

Thank you very much. I have solved my problem

1 Like

IDK how you fixed it but issue you are doing is that you are setting gun/hand angle to angle between gun/angle and cursor
And you should set gun/hand angle to Player.AngleToPosition(CursorX(),CursorY())

IIRC…: I have played around with the gun’s sprite’s points so it attaches better to the player. So now I got only this error :sweat_smile:


Notice the gap between the gun vs the player sprite when aiming at different directions! I was going to ignore it, but it would be incredible if I fixed it.
I tried to apply some “position” condition for the gun when facing a certain direction (IIRC…) but that only made the gun teleport across the screen when aiming to the left. I’m clueless again.

Center and origin point should be in same place on your gun

Actually NO
That would be solution if you would not rotate gun

Now issue is where you place your gun
It should be to center of player

i guess it’s an origin problem…
you should set the gun centering the handle e moving the origin at center to avoid the offset…
i also requested a feature to remove this problem.

“Center + Origin = the same” causes the offset crosshair bug I eliminated hours ago :stuck_out_tongue:

Pretty much fixed! Refer to photos:

1 Like

That is why i told you it should not matter
But it should to where you place it on player
But i see you figured it anyway