Vector Math Help

Hey, I have a vector math question that I am struggling to find an answer too. Unfortunately Chat GPT was unable to help me, so here I am… :smiley:

I am looking to create a snapping tool for a little in-game editor I am working on for my game. This is done in UE4.27, although i’m sure the solution is the same in any version of unreal.

I want to use a location, rotation and a grid spacing float variable to create a custom coordinate system. I then want to allow players to snap objects to the closest whole number point of that system.

To make things a little more complex I also have the ability to multi-select objects, and wish for a group of selected objects to also be snapped to this custom coordinate system. The group would use the bounding centre of all objects as the point that would need to match the whole grid coordinate, and the objects would maintain their position relative to each other as they were prior to the snap.

image
This is the little actor I made to represent the object that a player can place down and use as custom coordinates. As seen in the image, the actor can be placed as various angles also, so this would need to be accounted for (hence my mentioning location AND rotation earlier).

The above image is my final attempt with help from GPT, but it doesn’t work. This attempt also just uses a single actor, instead of a group, since my previous attempts at working with a group were unsuccessful, I wanted to see if I could get a single object working.

The Function initially checks for the existence of the grid object, and if it does not exist, it will simply use the unreal global coordinate system (i.e. it will use 0,0,0 for location and rotation inputs of the function).

Hopefully I have done a good job at explaining the desired outcome, and I would really appreciate anyone who may have some insight into my problem!

Thanks for taking the time to read!

You can generalize this quite easily using attachment, I think.

With multiple meshes, just attach them all to a centrally spawned pivot point ( easy with a single actor also ), then all you have to do, is transform that pivot.

There’s still a lot of design decisions to make, though…

Yeah theres a few ways to simplify the process of moving multiple objects. My main issue at the moment is getting ANY object to move correctly… xD

The Snap Vector/Float to Grid functions might be helpful here

image

image

Wow I didn’t even know these two functions existed… xD

I don’t see any way to use a custom coordinate system though, it seems like these only snap to the global unreal coordinate system?

Inverse transform vector, snap to grid, then re-transform result.

2 Likes

Any chance you could drop a quick pic of an example of this in chat? I see the inverse transform vector node but I have no idea what I would do with the M input on it.

thanks!

I believe this is the solution. :slight_smile:

ty <3

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.