Please help me in math

Godot Version

Question

how to get horizontal vector if i have diagonal vector and vertical vector.
Thank you.

2 Likes

Please help me understand your problem.

  • What are the two vectors you’re referring to as “diagonal” and “vertical”?
  • In what context are these vectors used?
  • What is your “horizontal” vector being used for?

If your only goal was a horizontal vector, you could just set the y-coordinate to 0.

1 Like

Vector2i(3, 5) + Vector2i(2,0) + Vector2i(0,2)
is that what you mean?
image

1 Like

I think if you could do a quick drawing of what you mean, that would be very helpful.

2 Likes

Pythagoras’s theorem maybe? could you elaborate please.

1 Like

Here is a little intro.

Look at the Tank Robot example. Basically subtracting 2 vectors gives you a 3rd.

Then you can get all the info you need using these methods of the vector class

3 Likes

I wanted explain my problem in detail. But accidentally i fixed the problem by trying the slide() method in vector3. slide makes y become 0. Diagonal vector that i mentioned is a distance from enemy to player. Horizontal vector is when player and enemy have same y value. And diagonal is when player y is higher or lower than enemy.

If theres any other way to make y become 0 when y axis is not Vector3.UP.
When y axis is Vector3(0.707107, 0, 0.707107) for example. I would love to know.

thank you very much for your answer. i really appreciate it

Yes… any vector that is slanted. But currently im using godot for 3d. Thank you very much

You are right. Im sorry. Thank you very much for your answer

Maybe because i suck at math. Pythagoras doesnt help me much since its only for vector length. Thank you very much

I will take a look. Thank you very much.

If you look at the Vector2 classes all the functions are there to calculate for you. No math required.

If you need further help, It would be good if you had a simple image of what you are trying to accomplish as I am still confused.

1 Like