How to give an inverted nbt tag to a mob?

Im having a problem where I need to grab the downwards motion of a player and transfer it to an upwards motion for another entity, I know how to give the Y motion of a player to an entity with the /data command, but I do not how to inverse it. Plz help


Solution 1:

You can use the execute store with scale to invert it by doing:

/execute store result entity <Target> Motion[1] double -1 run data get entity <Source> Motion[1]

We can also use scale inside the data command, but using it there makes the returning value an integer, making for example 0.9 be -1.0. We can avoid it by using the scale inside the execute command which let us choose the data type.