what is vector? and where to use it?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By learner
:warning: Old Version Published before Godot 3 was released.

know some basic python, also wrote some small scripts in past(web scrapping, brute force), now i want to move on game development, so choose go with godot.

i was looking GDscript syntax, came to this part:

# built-in vector types

var v2 = Vector2(1, 2)
var v3 = Vector3(1, 2, 3)

i don’t know what are vectors, and for what purpose these use?

is it related to physics,

I have done my graduation from ARTS. so never faced this word, neither in python,
can anyone explain what it is?
and what are uses of vector in gaming?

thanks.

:bust_in_silhouette: Reply From: hungrymonkey

Vector in godot is kinda like physics or transformation vectors.

It is pretty much a generalize data type in math that have tons of applications.

the docs are pretty helpful, you should read it

:bust_in_silhouette: Reply From: Zylann

A Vector2 or Vector3 represents the coodinates of a point in space, or a translation depending on how you use it. In other frameworks you can also find it named a Point2D, Size2D, sometimes simply a tuple of 2 or 3 numbers etc. They all are the same thing, but in Godot it gets its own naming because it is used a lot.

For example, player position in a 2D game will be stored in a Vector2 (x, y). In 3D there are 3 dimensions (x, y, z) so it would be a Vector3.

You can add and subtract vectors together. For example, moving a character requires to add a value to its X and Y coordinates:

# Moves 10 pixels to the right and 5 pixels up
position = position + Vector2(10, -5)

There is a whole field of mathematics dedicated to vectors (part of linear algebra) which is very useful to know in game developement.

You should (must!) read the documentation linked by hungrymonkey because it explains more about it :wink:

:bust_in_silhouette: Reply From: LeeJiwon

You can find out more about what vectors are and how they are used in Godot by referring to the following two links.