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:
...
6
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 ...
5
votes
Accepted
Unity3d: Find which gameObject is in front
You can check simple ahead/behind relationships using the dot product:
...
5
votes
Accepted
What direction does directional audio come from for a 2D view?
The spatial audio should be relative to the camera.
If you consider it, even in a 3D game, the audio is relative to the camera. Sounds that come from the right side of the screen are heard from the ...
3
votes
Movement velocity relative to a static object (Vector Maths)
The dot product between two unit vectors is:
+1 when the vectors are pointing in the same direction
0 when the vectors are perpendicular
-1 when the vectors are pointing in opposite directions
So, ...
3
votes
Accepted
How to align a hint arrow to point along a path?
It looks like your trouble isn't in computing the direction - it's that your arrow asset was imported with an unusual orientation, so when you use methods like LookAt or LookRotation they give you the ...
2
votes
Direction between objects (shortest distance around sphere)
A few issues come to mind as I read this:
Your movement is on the surface of a sphere, so travel direction
should be a tangent to this surface, not just a (to-from)
normalized, as that would point ...
2
votes
Random Direction Vector Relative To Current Direction
I've done this, and its not too hard.
Firstly, generate a random non 0 length vector. Normalise it.
Cross product with your current direction vector to create a rotation axis.
Generate a random ...
2
votes
Accepted
Raycast wrong direction
Currently your raycasting happens relative to your transform. Your transform is currently rotated so "forward" is now pointing downwards. If you want your raycasting to happens relative to the global ...
2
votes
Accepted
How to check if two normals/directions "look at" each other?
Given points P0 and P1 with normals N1 and N2...
...
1
vote
How to check if two normals/directions "look at" each other?
Well, you can compare the distances between origins (d1) and points offset by the normals (d2) (scaled by fraction of the ...
1
vote
Rotate Sprite in direction it is moving while beeing dragged
When you hold the mouse button down, begin tracking the location of the mouse.
Every frame, compare the current location with the location on the previous frame.
If the vector from previous to ...
1
vote
How to mirror a vector through some other vector?
Turns out you can rotate the direction using this formula without problems:
newDirection = Quaternion.Euler(0, desiredAngle, 0) * playerDirection;
1
vote
Accepted
Unity3d: Position a gameobject such that its forms a right angled triangle with other two gameobjects
Taking these two constraints:
"position C gameObject such that it forms a right angled triangle with A and B"
"I want the C to be along the local red axis of A"
We can solve this relatively easily ...
1
vote
Accepted
How to decrease the size of a distance?
"Mouse line up to the mouse cursor" is a vector, and vector could be normalized. Normalized vector is a vector of length 1. What this gives to us is that we can scale it to any length we want.
Simply ...
1
vote
How to decrease the size of a distance?
Not sure about blueprints but this is how i do it.
...
1
vote
Accepted
Bullet direction incorrect around sphere
transform.Rotate(x, y, z) rotates in local Euler angles. That means it applies a rotation of y degrees about the local y+ axis, ...
1
vote
Accepted
Make object face another object on a sphere
This can be done more simply than it might appear.
We can think of this as an orientation that points our local y+ (up) axis directly outward from the sphere, so our local xz plane is tangent to the ...
1
vote
Accepted
Create rotation in random direction from existing rotation
For anyone who is curious, here is what I ended up doing.
I created a new rotation using Quaternion.AngleAxis:
...
1
vote
Accepted
Calculating correct normal direction from multi-variable function
This trick
Vector3 normal = new Vector3(tangent.y, 0, -tangent.x);
works great in 2D, when we only have 2 perpendiculars to choose from. It's not the right ...
1
vote
Accepted
Flip x when direction of the movement changed in Unity
I suggest do not bind the flipping procedure to the Input since it is directly relevant to the moving direction of the body (Input may not change the body's moving ...
1
vote
Why is there a discrepancy between these two transform.up vectors?
I called the method that ran the Debug.LogError(obj.transform.up); inside a coroutine, the coroutine essentially had an off by one error and given that the object was moving in 90 degree steps and I ...
1
vote
How to rotate a local position offset based on a direction vector?
Since it looks like you're working in the 2D x/y plane here, you can use a cute little trick:
...
1
vote
Accepted
Get GameObject which instantiated me in Unity
You must attach a script to the prefab you instantiate and "inject" a reference of the gameobject which has instantiated the prefab as follow :
...
1
vote
How does this math behind converting angles to vectors work?
It works via repeated Rotations, you begin mentally with the Vector {1,0,0} then you rotate it along the Y-Axis the length of the vector is just one so you can get the new coordinates simply by ...
1
vote
Accepted
How does this math behind converting angles to vectors work?
First let's look at how to convert an angle (the yaw-angle) into a vector in two-dimensional space:
As you can see the y-value is the sine of the angle and the x-value is the cosine of the angle.
<...
1
vote
Accepted
Velocity Relative To A Vector
So I solved this in kind of simple way.
As I had the pointing vector(which in my specific case was y, but it doesn't matter that much) and I found out that I can ...
1
vote
Velocity Relative To A Vector
you can just convert the coodinates.
to do this, you have to use the normalized â as an base vector for the new coodinating system then use the 90º rotated ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
direction × 58unity × 21
vector × 21
movement × 11
mathematics × 10
rotation × 8
c# × 7
angles × 7
2d × 5
collision-detection × 5
physics × 5
linear-algebra × 5
transformation × 3
sphere × 3
java × 2
xna × 2
libgdx × 2
sprites × 2
ai × 2
input × 2
game-maker × 2
platformer × 2
random × 2
normals × 2
opengl × 1