Scaling the X axis of an object based on cursor position and the forward vector of the object

Hello,

I’m trying to scale the X axis of an object relatively to the cursor position in the 3D space, but only if the mouse cursor position increases/decreases along the forward vector of the object line, but my head just can’t get over it.
I also need to move the object to the front a bit, so the object is scaled only to one side and not on the entire X axis.

Could anyone please help me? Any help is greatly appreciated!

Break all your steps apart:

  • get the mouse input

  • accumulate it to some scalar value

  • use it to scale only your X

Once you have done that then you can use Debug.Log() to print out all the values along the way and reason about changes to your math.

That’s what i’ve kind of got, but the real issue comes when i want it to only scale if it moved along the forward vector line.

You can use Vector3.Dot() to see what fraction of any vector lies upon another vector.

Ah, yes. That’s not exactly what i want because then it will only scale if the mouse position is exactly along the forward vector.
I’m sorry for my really bad explanation, but what i’m trying to accomplish is for the object to scale if the mouse moved anywhere on screen along the line.
Example: The forward vector is 0.75,1,0 and i need to scale the object if the mouse position moved along the vector line, but anywhere on the plane. That is that it will be scaled only if the position changed along the X (0.75) and Y (1) axis, it wouldn’t scale if it only changed along the X axis unless it’s 0 in the forward vector.

I hope this is a much better explanation.

Mathematically it will be impossible to ever move the mouse (except by luck) precisely ON that vector.

You can use Dot to see what fraction of it is on that vector and make reasoned decisions about what to do.

Sorry for the late reply, but actually i’m trying to scale the object only if the mouse moves along the forward vector line, but anywhere in the world and i don’t think Dot would do the trick unless i’m missing something.
Let me try to explain it with drawings:


The square is an object, the blue dot is the mouse cursor, which is somewhere around the object (note that it can be far away too, it’s just not touching the object.), and in the left corner is where all the axes are heading. We won’t count the Z axis for this one as i won’t use this one at all and the forward vector of the object is exactly 1,0,0. And lastly the arrow below the object is where the forward vector is heading.

Now if we only one axis from the forward vector is bigger than 0 and the rest is equal to zero i can simply just calculate the distance between the object and the cursor position where where i’d multiply each axis distance by it’s relative axis in the forward vector and then calculate the scale value for the object. Like this i can move the mouse anywhere i want, but only if the moves along the X axis (it can move along the other axes as well here) the object actually scales.

The problem comes when multiple axes are bigger than 0 in the forward vector:


Here the forward vector is 0.75,1,0. I want the object to scale if the cursor moved along both X and Y, but i can’t just multiply the distance by the forward vector because like that it would still scale if the cursor moved along only one of those axes which is what i don’t want and i have no idea how to solve this one.

The drawings are awful, but i hope it at least explains the problem i’m facing. If you can help me i’d be grateful.

6998264--826844--1.png
6998264--826847--2.png