Skip to main content
3 votes

Relative angle in degrees between 2 lines

Did you try even a cursory search for this? It's pretty standard vector math: ...
DMGregory's user avatar
  • 136k
2 votes

How can I launch a GameObject at a target if I am given everything except for its launch angle?

I modified DMGregory and Evorlor's solution a bit as I wanted a 3D arc and wanted to be able to apply a minimum speed if the provided speed wouldn't reach. ...
Tim's user avatar
  • 21
2 votes

2d starship combat, hit chances based on bearing and speed (vector)?

You simply need a parametrical equation. A good way to get how different the 2 ship's angle is is to use dot product on the ship's direction vector and the normalised version of the vector pointing ...
Bálint's user avatar
  • 15k
2 votes

Unity C# - Rotate smoothly an object towards the direction given by input

I don't see why you need a coroutine; I think you need Quaternion.Slerp(). Unity give an example of what you want to do in its documentation.
Droppy's user avatar
  • 214
2 votes

Gravity vector and forward vector to local heading (yaw), pitch and roll

I will try to break down the step-by-step questions I'd take to solve this problem, with the hope it helps you to understand how to go about solving vector-related problems in the future. Note: I'll ...
Jimmy's user avatar
  • 9,039
2 votes
Accepted

3D Thrust velocity

Trigonometry As stated in this article, 3D rotations (rX, rY, rZ; for their respective axes)...
clabe45's user avatar
  • 408
2 votes
Accepted

How to rotate object just like in the scene?

The (local) transform gizmo shows you rings of possible rotations from the current orientation, about the current local x, y, and z axes respectively. The Inspector / ...
DMGregory's user avatar
  • 136k
2 votes
Accepted

Slerp to slerp smoothing

I hadn't actually aligned in CatmullRom, it was one of my other tests. It got lost in all the messy code. The problem was solved by aligning the start and end points of the spline input. (params: pre, ...
John Smith's user avatar
2 votes
Accepted

How to clamp a mouse angle within a field of view range of the facing direction

Looks like you need to compare angles and work out their difference. Here's one way to do it: ...
DMGregory's user avatar
  • 136k
2 votes

Calculate aim angle dead zone range

Think of the gun as of being parented to the player (conceptually, it inherits player's transform (rotation)). That way, you only need to worry about the local angle (in local space, it's as if the ...
Filip Milovanović's user avatar
2 votes
Accepted

Rotating only 2 axes of rotation quaternion to "point" in a direction

Following DMGregory's excellent answer and posts linked, I now understand the issue. I have implemented his function provided in one of those answers, and it works beautifully. This is my solution: I ...
Kyohei Kaneko's user avatar
2 votes
Accepted

How do I apply real time physics to a 2D game in Java?

Don't worry about a package you want to use having more stuff in it than you need. It's unlikely a package will have just what you need... but no more than that. What's more important is if it can do ...
Almo's user avatar
  • 6,708
2 votes
Accepted

Using both look_at and flip_h in Godot

flip_h is making your arm point in the "opposite" direction when you use look_at. A quick, simple solution would be ...
Tanaki's user avatar
  • 252
1 vote
Accepted

How to wrap a components position using angles (i.e horizontal compass)

I'd junk this code and do it in a simpler way. ;) ...
DMGregory's user avatar
  • 136k
1 vote
Accepted

Clockwise / counter-clockwise convention for Vector2.Rotate(float angle)

I was tempted to vote to close this as primarily opinion-based, but we may be able to provide an evidence-based argument here. I'd recommend that your method rotate counter-clockwise for positive ...
DMGregory's user avatar
  • 136k
1 vote
Accepted

Top-down 2D push angle velocity

The two options are: 1.) NPCs run away from the player. With this one you just need to take the vector going from the player to the NPC, normalize it and set the NPCs velocity to this vector 2.) ...
Bálint's user avatar
  • 15k
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
  • 136k
1 vote

Quaternion angle calculation

Calculate the "shadow" on i,j plane $$A\alpha= \sqrt{(Ax)^2+(Ay)^2}$$ Get the γ angle $$\gamma = tan({A\alpha \over Az})$$ Middle solution : $$\alpha'=tan({Ay \over Ax})$$ $$\beta'=tan({Ax \over Ay})...
Sky-08's user avatar
  • 23
1 vote
Accepted

360 degree Shooting using Pythagoras problem Unity 2D C#

transform.rotation is a Quaternion, not a collection of angles. Accessing individual components of a quaternion is almost never ...
DMGregory's user avatar
  • 136k
1 vote

Top down off-screen indicator

use the arctangent to find the angle angle = Mathf.Atan2(z2-z1), x2-x1) * Mathf.Rad2Deg; The output is in Radians, so multiplying by ...
Kyy13's user avatar
  • 740
1 vote

How to rotate object just like in the scene?

It seems you are trying to tell apart the local from the world space. From the scene, you can press a button next to pivot, to tell apart the local from the ...
Tom Tsagkatos's user avatar
1 vote
Accepted

How can I set only the players X rotation to 0 in Quaternion.Slerp in Unity?

Quaternion.LookRotation looks along the vector you pass it. So if you want that rotation to twist only in the horizontal plane, lock the input vector into that ...
DMGregory's user avatar
  • 136k
1 vote
Accepted

Check whether object is looking in between a minimum and maximum angle in 3d Space

You'll need to get the current direction vector of the object (you can get this with transform.forward in Unity), vectors that point in the directions you care for ...
Bálint's user avatar
  • 15k
1 vote
Accepted

Why don't Sin and Cos give expected results when rotating off axis around a non uniform shape?

The length of the lines must always equal the length of the side. If you however multiply sin(angle) by the width of the rect and ...
Bálint's user avatar
  • 15k
1 vote

Travel over step angle

Thanks to DMGregory for the sage advice. I needed to get my vectors into the correct world space coordinates . The working code is below, it needs clean up but it works like a champ. ...
NoiseyAgent's user avatar
1 vote
Accepted

Restrict Up/Down rotation, detect angle upwards/ downwards

With the somewhat limited info you wrote, you could try: Calculate 3D points (or 2D) for the edge Target.position's, by the allowed maximum angles (-45 and +180 degrees). Resolve a point exactly in ...
Stormwind's user avatar
  • 1,061
1 vote
Accepted

Unity look at rotation on one axis only problem

Solved it, the working code is below: ...
John Smith's user avatar
  • 1,255
1 vote

Calculating angle to aim at target results in over/under aim depending on whether target is below/above

Sounds like you just always need to use the players eye position instead of the camera position for the calculation.
James Lambert's user avatar
1 vote

2d starship combat, hit chances based on bearing and speed (vector)?

Using the angles you provided as example, I took the liberty of assuming a few other data / scenarios. Let's say you want a 100% hit chance when the angle difference is 0, and have the "good extremes"...
Franconstein's user avatar
1 vote
Accepted

Unity 3D - Rotate (smoothly) towards a target

There's a few functions for this already in Unity 3D: Vector3.RotateTowards https://docs.unity3d.com/ScriptReference/Vector3.RotateTowards.html ...
Stephane Hockenhull's user avatar

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