Skip to main content
The 2024 Developer Survey results are live! See the results

# Tag Info

## Hot answers tagged vector

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, ...
• 15k
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 ...
• 16.3k
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 ...
• 3,126
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 (...
• 507
27 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 ...
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 ...
• 673
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. ...
• 5,283
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 ...
• 136k
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: ...
• 136k
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

### 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 ...
• 4,785
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: ...
• 3,241
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. ...
• 1,506
10 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 ...
• 101
10 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....
• 407
8 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 :)
• 181
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 ...
• 803
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, ...
• 20.2k
7 votes
Accepted

### Unwanted roll when rotating camera with pitch and yaw

As I explained above, this is not an issue with quaternions. Quaternions just represent your rotation. The problem is that you have mutually conflicting goals for this rotation: The camera can look ...
• 136k
7 votes
Accepted

### Random Direction Vector Relative To Current Direction

Random direction relative to current direction: Assuming you already have an initial direction vector prepared, as per DMGregory's comment on the OP: Generate a ...
• 2,104
6 votes
Accepted

### Direction vector to quaternion

From http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/ ...
• 3,729
6 votes
Accepted

### Is it possible to calculate a direction vector without sqrt?

If you want a correct mathematical result (correctly rounded to within floating point precision), a square root is the way to go. It's true that it's more expensive than a multiply, but it's still ...
• 136k
5 votes
Accepted

### Does AddForce continue to add force indefinitely?

AddForce will apply a force for the current update cycle. The force is applied to the RigidBody for that update cycle, then cleared. At the beginning of each ...
• 73.3k
5 votes
Accepted

### Find the closest point on a ray

Closest distance point segment: ...
• 368
5 votes
Accepted

### How to calculate vector of projectile initial velocity

Assume your variables are: initial velocity , initial position , and target position . First, choose your initial y-velocity, and calculate the time it requires to reach its target on the y-axis ...
• 149
5 votes
Accepted

### Need help with getting a direction vector between two given points

In your situation you need a simple subtraction, with a normalization. vectDistance = B - A vectDirection = vectDistance / lenght(vectDistance) This will give ...
• 16.3k
5 votes

### Calculate vector3 global point projecting it in local space using Unity and C#?

Let's say you have a trasnformed coordinate system defined by a quaternion rotation, and vector3 position. For example, the ...
• 27.3k
5 votes

### If a 3D vector represents a point, how can it have a length?

A vector can represent a line between two points in 3d space (direction and distance) or a location in 3d space (length is the distance from origin). If you have point A, and point B, then B-A = AB = ...
• 2,669
5 votes

### Why rotating an object only on its local X axis result in sudden 180 degrees changes in Y and Z axis rotation values

The thing to remember about Euler angles is that they're a fiction the engine generates on demand for our sake. They're not the ground truth of how rotation is stored inside the engine (that uses ...
• 136k

Only top scored, non community-wiki answers of a minimum length are eligible