How to calculate a vector for movement when not using a uniform speed value?

It’s been a long time since I did maths in college and I’m struggling to find the words to describe this properly so I drew a picture.

So I’ve got a vector for a jump V1 and a vector for movement V2, adding them gives me vector x, and averaging them point y, but I need point z. I feel like there should be some way to calculate z by normalising x and doing something with the magnitudes of V1 and V2 to calculate a speed value each tick but I’m struggling with that final step.

Any help or a point in the right direction would be greatly appreciated.

z=y*1.25

1 Like

That simple huh?

I was massively over thinking this, thanks for the help.

So this isn’t exactly what I was looking for. Maybe I can do a better job of explaining, and in doing so I might have worked it out.

For the sake of simplicity say:

``````V1 = (0,1)
V2 = (1,0)
VectorX.magnitude = sqr(1^2 + 1^2) = 1.414
VectorY.magnitude = sqr(0.5^2 + 0.5^2) = 0.707
VectorZ.magnitude = sqr(0.707^2 + 0.707^2) = 1
``````

So as 1.414 * (1 / 0.707) = 1, With Vector Z being the result if you normalised Vector X. Could I then extrapolate on this and simply multiply the magnitude of my intial vector by the magnitude of it’s average to produce an equivalent value to Z.

For example using a vector from (0,0) to (1,3) giving:

``````X.magnitude = 3.162
Y.magnitude = 1.581
Z.magintude = 3.162 * (1 / 1.581) = 2
``````

Why do I get the feeling I’ve just gone a really long way round to what could have been Z.magnitude = (vector.x + vector.y) / 2

And does this mean what I did initially was correct but I must’ve messed something else up because it didn’t behave as I expected:

``````float speed = (rigidbody.velocity.x + rigidbody.velocity.y) / 2;
rigidbody.velocity = rigidbody.velocity.normalized * speed;
``````

I am still a bit confused about what you are trying to accomplish. Why do you need to find point “z”? What does the red line represent in your initial diagram?

If you have an object’s x velocity and and an objects y velocity, you can just add those two vectors together to get the final velocity vector. The object’s instantaneous speed will be the magnitude of that vector.

I confused things by saying point z. What I meant is I want the vector to z given vectors v1 and v2 where vector x is v1 + v2. Vector z represents an attempt at doing something akin to normalising, but rather than a simple magnitude of 1, I want a magnitude representative of the seperate magnitudes of v1 and v2 as they will be continuously changing, so I cannot simply normalise v1 + v2 and multiply it by a value for speed. The red line represents the curve of a circle that intersects both v1 and v2 at their end points.

Good to know.

You will need to be more specific. What does “representative of the seperate magnitudes” mean? What relationship do you want.

This alone is not enough information. You can draw infinitely many circles through two points in space. Which point z are you trying to find?

In your original post, you mentioned that V1 was a jump velocity.

It is very common to calculate horizontal velocity and vertical velocity separately and then add the two vectors together to get the final velocity. As Vy changes from frame to frame, the magnitude of the velocity vector (i.e. its speed) will change.

I understand what you’re saying about the circles, was just trying to visualise what I was thinking and it probably ended up hurting more than helping.

Following on from what you’re saying about the jumping at the bottom, what I’m trying to overcome is that if you jump and move at the same time the player moves faster than if they were just moving or just jumping. Similar to the if you had a top down game and the player pressed up and left at the same time they’re move faster than just pressing up or left. To fix this you would either normalise the input or velocity then multiply it by the speed. I’m trying to replicate this in a situation where there is no simple speed variable, and at the risk of throwing more confusion into the mix here’s another analogy:

If you had an analog input but rather than both axis being -1 to 1 one of the axis was -3 to 3 instead. How would you calculate the magnitude of the input vector if the analog control was being pushed fully in any direction?

In the both being -1 to 1 example it would always return a magnitude of 1, where as in the other it would return a value between 1 and 3.

I think I understand now… maybe…

``````    // combine the vectors into a single vector and clamp it
Vector3 z=Vector3.ClampMagnitude(new Vector3(V1.x,V2.y,0),maxSpeed);
// move the clamped components back to their source vectors
V1.x=z.x;
V2.y=z.y;
``````

But life would be so much easier for you if you didn’t have separate vectors.

I found the formula I was looking for geometry - How to get the radius of an ellipse at a specific angle by knowing its semi-major and semi-minor axes? - Mathematics Stack Exchange