[SOLVED] I can't figure out how to make the gun float

How do I make a gun float and hover around the player following the cursor. I looked into some videos but I’m really just too lazy to research it more. So, I came here. Everyone else is asking serious questions while I can’t figure out this one simple thing.

You want that sprite to follow the cursor or to hover over the player? Because they are different things: if the object is following the cursor and the cursor is around the player THEN the object is around the player, but not if the user move the cursor far away from the player character. So, you need to be more specific.

Sorry, let me clarify. So, I have the player in the center of the screen. I have a gun sprite that can point at the cursor. Currently, I can get the gun to be on top of the character’s sprite, what I want to do is to have the gun point at the cursor and be able to move in a complete circle around the player instead of on top of the player. So, tl;dr, I want the gun to move in a fixed circle, with it’s position on that circle decided by the position of the cursor on the screen.

This is a minimal implementation of a floating sword I made with this 3 actions:


It calculates and stores the angle from the player sprite to the cursor in a variable and then use that data to put the sword around the player in the right angle, as well as rotate the sword sprite itself in the right angle.

Important notes:

  • This works for a sword sprite depicting a sword in horizontal position and pointing right.
  • The center and origin points of the sword sprite are set at the base of the handler of the sword, this is needed in order to work properly.

You can download the project from here: floating_sword

Hope this helps!

Btw, the result look like this:


1 Like

Alright, thanks! I appreciate the help