How can i implement an object that follows the mouse that is rotating around character

There is a game called “deepest sword” where you can move your sword around the character by moving the mouse. I thought of ways to implement this and cant find one
can somebody explain how to do it correctly or in general how to implement it?

    • List item

There are a few ways you could implement the ability to move a sword around a character based on mouse movement. One way to do this would be to use the Unreal Engine’s built-in physics system to simulate the sword’s movement.

Here is a general overview of one way you could implement this:

  1. Create a sword mesh and attach it to the character’s hand using a socket or bone.
  2. Create a physics constraint (e.g. a spring constraint) between the sword and the hand socket/bone.
  3. In the character’s blueprint, create a custom event that is triggered by mouse movement.
  4. In this custom event, use the mouse movement data to set the target position and rotation of the physics constraint. This will cause the sword to move and rotate based on the mouse movement.
  5. For more realistic movement, you can also add some damping to the constraint so that the sword doesn’t move too quickly or too far from the target position.

Optionally, you can also add some collision detection to the sword so that it will interact with other objects in the game world.

It’s worth noting that this is just one way to implement this feature, and there may be other ways to achieve the same result, depending on the specific requirements of your game.

Thank you so much for such detailed answer!
the way i tried to implement it was by creating a spline around a character that follows him all the time, and make the sword move through the spline by accepting mouse input instead of creating a timeline and making it move with it.
Anyways thank you so much!

1 Like

No worries! I am happy you found my answer helpful! :slight_smile:

Hello again. If i may ask, how to exactly add physics constraint beetwen an actor(sword/weapon) and a bone? i’ve only had expirience creating them on the levels and worlds beetwen random objects and not player characters

nah, i still dont understand how to attach physics constraint to a sword and socket

This is a good resource to learn more about the subject. Let me know if you have more troubles setting it up after reading about Physics Constraint Component User Guide | Unreal Engine Documentation

thank you a lot for this documentation, with it i accomplished what i wanted, now i will go to making a system that moves it with mouse as i said before)
any tips beforehand?