38
votes
Benefit of using Vector2 data type over separate x & y variables
First of all, it's way less clutter. If you have a position, a velocity and an acceleration, that's already 6 variables you have to deal with, 9 in 3d.
Secondly, and this is the most important part, ...
36
votes
If a 3D vector represents a point, how can it have a length?
Does that mean that the magnitude is simply it is distance from the origin point (0, 0, 0)?
That's exactly that.
Among other things, a vector can represent a point (a position), a direction and/or a ...
35
votes
Accepted
How can I rotate an object based on another's offset to it?
The answer is actually pretty easy if you do the math. You have a fixed distance of Y and a variable distance of X (See Picture 1). You need to find out the angle between Z and X and turn your turret ...
30
votes
Accepted
How can I find the perpendicular to a 2D vector?
I always forget how to do this when I need it so I wrote a couple of extension methods.
...
28
votes
Why can't I use the operator '>=' with Vector3s?
Defining >= for a Vector3 type makes no sense. What determines if one vector is greater than another? Their magnitude or ...
28
votes
Accepted
How can I get the normal vector for a plane from a set of vertices?
You could easily find the normal by calculating two vectors, V1 = P2-P1, and V2 = P3-P1, and then find the cross product N = V1 x V2. Then you normalize N. Depending on the ordering of the vertices (...
20
votes
Accepted
If a 3D vector represents a point, how can it have a length?
Does that mean that the magnitude is simply it is distance from the origin point (0, 0, 0)?
The tl;dr answer may be: Yes, you can imagine it like that.
But I'm not sure whether this might not lead ...
17
votes
Accepted
How do I tell if my enemy can see my player?
The dot product of two vectors can tell you if they face each other or not. First vector can probably be the enemies view direction the second one should be a vector pointing from player's position to ...
16
votes
Accepted
How do I interpret the dot product of non-normalized vectors?
Others have pointed out how you can use the sign of the dot product to broadly determine the angle between two arbitrary vectors (positive: < 90, zero: = 90, negative: > 90), but there's another ...
16
votes
Accepted
Why can't I use the operator '>=' with Vector3s?
To simplify the answer, Vector3 is a custom struct provided by the UnityEngine namespace. ...
16
votes
What are some good examples of the practical usages of cross product in game development?
Generating Normals
As Maximus Minimus notes in the comments, when we have a mesh without normal vectors (say just raw vertex positions from a procedural generator or 3D scanned point cloud), we can ...
15
votes
Accepted
How can I "zero out" velocity in an arbitrary direction?
This is pretty simple linear algebra. You can make a little helper method for it:
...
14
votes
Benefit of using Vector2 data type over separate x & y variables
Compare the function signatures of both RotatePoints versions.
Lone variables:
...
13
votes
Accepted
What's the 'proper' way to get unit vectors?
A Unit Vector is of length 1.
A given vector can be converted to a unit vector by dividing it by it's magnitude. (With the exception of course that a zero length vector can not be converted).
Note ...
12
votes
Accepted
How can I check if a player-drawn line follows a path?
Here's a vector-based solution. I haven't tried it, but it seems fine conceptually.
Theory
I gather you've stored the shape as line segments. Here's the letter A represented with three line segments....
11
votes
Accepted
Why does a unit vector show direction?
First we get a vector from B to A, as in the following picture:
Now we have a vector that tells us how to get exactly from B to A. In code it looks something along these lines:
...
11
votes
Benefit of using Vector2 data type over separate x & y variables
Readability > Writeability
I feel like it's just slow me down and barely has any benefit other
than organizing your code.
You are correct in that it (slightly) slows you down writing that code. ...
10
votes
How can I draw a line of certain length and direction?
You can simply get the vector pointing in the right direction, then scale it by the distance you want and add that to the initial point. This will define a new end point for your line.
...
10
votes
Accepted
Does vector transformation order matter?
Because of the linearity (aka distributive property) of vector addition and matrix multiplication, it doesn't matter! Yay!
...
10
votes
Accepted
Moving a 2D object along circular arc between two points
You can use Bezier Curves.
Given 2 given points, you have to define one third point yourself that controls where the curve is made. In your example you can create the point between your two given ...
9
votes
Accepted
What is a direction vector and why should it be normalized?
A 2D vector has two values (x and y), and it basically says how far you go from the point of origin in the x- and in the y-...
9
votes
Accepted
Unity: transform.LookAt(target) not "looking at" target?
The Problem:
Your eyes default rotation makes them look to the negative X axis.
However, Transform.LookAt() rotates the transform, so that the Transform.forward looks at the target.
The Transform....
8
votes
Accepted
How to find point on a circle that's opposite another point?
Calculate a vector from B to A, normalize it (divide by the vector's length), then multiply by the circle size:
...
8
votes
If a 3D vector represents a point, how can it have a length?
Does that mean that the magnitude is simply it is distance from the origin point (0, 0, 0)?
You can see it that way, but only seeing it that way may lead to a wrong understanding.
First of all, a ...
8
votes
Benefit of using Vector2 data type over separate x & y variables
Operator overloading.
Vector v3 = v2 + v1;
There is now only one place in your code where you have to write, test and debug vector addition, as opposed to tens, ...
7
votes
What are normal, tangent and binormal vectors and how are they used?
I know this is old but i would like to add a little practical information.
As stated by others but more specifically related to graphical programming.
A Normal aka (a surface normal) is orthogonal to ...
6
votes
How can I find the perpendicular to a 2D vector?
If , then a-perp obtained by a counterclockwise rotation by 90 degrees, i.e.,
See this link :)
6
votes
How do I convert two vectors into a bounding box with 8 vertices?
For an axis-aligned bounding box represented by a minimum and maximum corner, you can extract six pieces of information, xMin, ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
vector × 697mathematics × 183
unity × 164
c# × 102
rotation × 82
2d × 69
linear-algebra × 60
c++ × 56
3d × 56
physics × 54
movement × 54
xna × 47
matrix × 42
java × 38
quaternion × 35
collision-detection × 33
angles × 29
geometry × 24
opengl × 22
libgdx × 22
transformation × 21
direction × 20
coordinates × 17
javascript × 16
camera × 16