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: ...
Lasse's user avatar
  • 3,241
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 ...
CosmicGiant's user avatar
  • 2,094
5 votes
Accepted

Unity3d: Find which gameObject is in front

You can check simple ahead/behind relationships using the dot product: ...
DMGregory's user avatar
  • 134k
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 ...
House's user avatar
  • 73.2k
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, ...
DMGregory's user avatar
  • 134k
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 ...
DMGregory's user avatar
  • 134k
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 ...
Bram's user avatar
  • 3,729
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 ...
ErnieDingo's user avatar
  • 1,150
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 ...
Jasper Citi's user avatar
2 votes
Accepted

How to check if two normals/directions "look at" each other?

Given points P0 and P1 with normals N1 and N2... ...
Bram's user avatar
  • 3,729
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 ...
Kromster's user avatar
  • 10.6k
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 ...
Natalo77's user avatar
  • 679
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;
Jacob's user avatar
  • 2,532
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 ...
DMGregory's user avatar
  • 134k
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 ...
Ocelot's user avatar
  • 1,433
1 vote

How to decrease the size of a distance?

Not sure about blueprints but this is how i do it. ...
Native Function's user avatar
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, ...
DMGregory's user avatar
  • 134k
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 ...
DMGregory's user avatar
  • 134k
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: ...
DRiFTy's user avatar
  • 576
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 ...
DMGregory's user avatar
  • 134k
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 ...
Tolga Şen's user avatar
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 ...
confuzzled's user avatar
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: ...
DMGregory's user avatar
  • 134k
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 : ...
Hellium's user avatar
  • 2,949
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 ...
user5716904's user avatar
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. <...
Philipp's user avatar
  • 119k
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 ...
Adrians Netlis's user avatar
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 ...
Bruno Vieira Costa's user avatar

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