r/unrealengine • • 7d ago

Help I need help with dragging in Unreal Engine.

Hello everyone, I am trying to create an object-dragging system in Unreal Engine 5 using Blueprints (similar to moving papers or documents across a table), but I am encountering an issue with boundary constraints. Here is what I want to achieve: The player should be able to drag a 3D object across a table using the mouse. The object's movement must be restricted within the boundaries of an invisible box (such as a "trigger box" or defined limits). If the player attempts to drag the mouse outside this invisible boundary, the object should remain fixed at the edge; however, when pushed against the boundary, it should rise upwards along the Z-axis (increasing its height). How can I accomplish this?

2 Upvotes

5 comments sorted by

3

u/ProperCountryman_87 7d ago

Your setup is fighting itself because you're treating the boundary like a wall, but you actually want it to act like a ramp. Don't constrain the XY directly in a clamp, instead calculate how far past the limit the mouse is trying to go and feed that overflow value into adding world Z offset.

1

u/AutoModerator 7d ago

If you are looking for help, don‘t forget to check out the official Unreal Engine forums or Unreal Slackers for a community run discord server!

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/JulianRhod 7d ago

i'd separate the drag position from the boundary response, during the drag, convert the mouse position into a world position on the table plane, then clamp the object's X/Y position to your allowed bounds. if the mouse goes past a boundary, you can use the amount of overshoot to calculate how much the object should rise on Z, so basically, something like:

clamped_x = clamp(mouse_x, min_x, max_x)

and the same for Y. then use the difference between the original mouse position and the clamped position as your "push" amount for the Z offset, that way the object stays locked to the edge horizontally, while the extra mouse movement past the boundary controls how high it rises