Questions in topic: "angles"
http://answers.unity.com/questions/topics/single/1363.html
The latest questions for the topic "angles"Perpendicular point to two vectors
http://answers.unity.com/questions/1734147/perpendicular-point-to-two-vectors.html
Hello,
I'm struggling how to find A' vector given A and B vectors with direction from A to B that A' will be perpendicular to B. Below are screens of how I see it but can't find a way to actually calculate it.
Also, I was trying to find the middle cube that is most in front from the samples (in this case it would be 5th cube starting from A) and then trying to move the others cubes so tey aligns in line with that 5th cube giving me a straight line with a preserved relative position of each one so move them only one axis until aligned. But can't wrap my head around this one too...
Could anyone help me with that?
P.S. Sorry if the explanation is not good. It's hard for me to wrap it up in my head right now.
![alt text][1]
[1]: /storage/temp/160250-sample2.pngpositionvector3anglesSun, 24 May 2020 10:40:44 GMTstychuContinuously rotating by 90 doesn't get me the initial angle
http://answers.unity.com/questions/1726920/continuously-rotating-by-90-doesnt-get-me-the-init.html
I have a game object rotating 90 degrees every tow seconds, making the object to have 4 possible values for its Z rotation. Since the initial Z rotation is 45, the other values would be 135, 225, and 315.
Every time the game object rotates, it looks for its current Z rotation in a Dictionary: <br>
static public Dictionary<int, string> rotDirection = new Dictionary<int, string>{
{45, "NE"},
{135, "SE"},
{225, "SW"},
{315, "NW"},
};
How ever, it's not finding the initial value (45) since what it gets in the rotation is actually 44. Why is this happening?
float timer;
void FixedUpdate()
{
timer -= Time.deltaTime;
if (timer <= 0.0f)
{
timer += Constants.cannonRotationTime;
//transform's initial (z) rotation is 45
transform.Rotate(0.0f, 0.0f, 90);
int angle = (int)transform.rotation.eulerAngles.z;
Debug.Log("Angle: " + angle + ", direction: " +
(Constants.rotDirection.ContainsKey(angle) ?
Constants.rotDirection[angle] : "*NOT FOUND*"));
}
There is another odd thing. If I set the initial (Z) rotation of the game object to 135 all the values are found, it rotates to 45 instead of 44:
![alt text][1]
Now, if I set it as 225 or 315, no new rotation makes sense, this is what I get:
![alt text][2]
Why is this happening and how can I avoid it?
[1]: /storage/temp/158653-capture-20200505-03.png
[2]: /storage/temp/158654-capture-20200505-02.pngrotationeuleranglesanglesz-axisThu, 07 May 2020 09:33:26 GMTbaleadappAplying all 3 axes on object like in inspector causes gimbal lock (different from other rotation problems),Rotate all angles of an Object to an specific angle cause gimbal lock
http://answers.unity.com/questions/1725296/aplying-all-3-axes-on-object-like-in-inspector-cau.html
I have a script, that can give an object all axis of rotation simulat to the transform rotation x,y,z in the Inspector.
So i want to instantly change the rotation to the degrees i give in the inputFields.
forExample
float x = float.parse(inputFieldX.text);
float y = float.parse(inputFieldY.text);
float z = float.parse(inputFieldZ.text);
...
void ApplyRotation(Transform object, float x,float y, float z){
object.eulerAngles = new Vector3(x,y,z);
}
but this causes in some cases the Gimbal Lock and Z and Y rotation does the same.rotationanglesgimbal-lockSun, 03 May 2020 22:26:02 GMTdaggldaHow to get the angle a 2D character is facing?
http://answers.unity.com/questions/1719735/how-to-get-the-angle-a-2d-character-is-facing.html
Hello, I am making a game where the main character can transfer to flying mode when jumping at a high speed. But I have tried so much to get this flight working.
I want him to slow down when going towards the sky and speed up when going towards the ground.
this isn't working, but here is my code
if (flyingRight)
{
if (isPitching)
{
rb.AddTorque(flightInput * 0.5f);
}
Debug.Log(transform.rotation.z);
//
//if (transform.rotation.eulerAngles.z > 0)
if (gameObject.transform.localEulerAngles.z > 0 && gameObject.transform.localEulerAngles.z < 180)
{
flightSpeed -= flightGravity * Time.deltaTime;
//flightSpeed = 0;
// Debug.Log(flightSpeed + "test");
} else if (gameObject.transform.localEulerAngles.z < 360 && transform.rotation.z > 180)
{
flightSpeed += flightGravity * Time.deltaTime;
//flightSpeed = 0;
//Debug.Log(flightSpeed + "test");
}
GetComponent<Rigidbody2D>().velocity = transform.right * flightSpeed;anglesflyingSat, 18 Apr 2020 01:38:51 GMTAmras789Orbiting Crosshair issue when trying to stop at a specific angle
http://answers.unity.com/questions/1717329/orbiting-crosshair-issue-when-trying-to-stop-at-a.html
Hi Guys,
I am pretty new here and I recently followed a tutorial to get me onto Game Development again. I have been working on a simple 2.5D game where the main player character is able to shoot spheres for the time being. I have managed to implement a crosshair that rotates around the player and managed to get it to stop when it reaches 90 and -90 degrees using the mouse.
However the issue I am having is when I move the mouse fast the crosshair seems to add more or less rotation which means on the next frames it does not stick to the 90 and -90 degrees I desire.
Image 1 - what I want to happen:
[Image 1][1]
Image 2 - What happens if I move the mouse fast:
[Image 2][2]
Code is below:
public class CrosshairManager : MonoBehaviour
{
[SerializeField]
private Transform _pivotPosition;
[SerializeField]
public float yOrbit = 0;
[SerializeField]
public float yOrbitOver, _oldAngle, _angle;
[SerializeField]
private bool _goingUp = false, _goingDown = false, _stop = false;
public static Vector3 RotatePointAroundPivot(Vector3 point, Vector3 pivot, Quaternion angle)
{
return angle * (point - pivot) + pivot;
}
// Update is called once per frame
void FixedUpdate()
{
//Work out angle from crosshair position and mouse position
Vector3 crosshairVector = Camera.main.WorldToScreenPoint(transform.position);
crosshairVector = Input.mousePosition - crosshairVector;
_angle = Mathf.Atan2(crosshairVector.y, crosshairVector.x) * Mathf.Rad2Deg;
//Set boolean flags to see if mouse is going up or down
if (_angle > 0)
{
_goingUp = true;
_goingDown = false;
}
else if (_angle < 0)
{
_goingDown = true;
_goingUp = false;
}
//Check if mouse is going up or down and add angle to yOrbit
if (_goingDown && yOrbit > -90)
{
Debug.Log("Going Down");
yOrbit += (_angle);
}
else if (_goingUp && yOrbit < 90)
{
Debug.Log("Going Up");
yOrbit += (_angle);
}
//Check if yOrbit (angle of crosshair) is over 90 and stop it in place
if (yOrbit >= 90.0f)
{
yOrbitOver = yOrbit - 90.0f;
Debug.Log(yOrbitOver);
_angle = _angle + yOrbitOver;
yOrbit -= yOrbitOver;
_stop = true;
}
//Check if yOrbit (angle of crosshair) is below -90 and stop it in place
else if (yOrbit <= -90.0f)
{
yOrbitOver = yOrbit + 90.0f;
Debug.Log(yOrbitOver);
_angle = _angle - yOrbitOver;
yOrbit -= yOrbitOver;
_stop = true;
}
//If within desired angle restraints then set stop to false and allow movement
else
{
_stop = false;
}
//Rotate the corsshair around the pivot point
if (_stop == false)
{
transform.position = RotatePointAroundPivot(transform.position, _pivotPosition.transform.position, Quaternion.Euler(0, 0, _angle));
}
}
}
[1]: https://drive.google.com/open?id=19dSY_UgH618HA8N8kHf0k2WDnh5ET4D7
[2]: https://drive.google.com/open?id=1sr3r2_dxMk6KKDLnJ5xhmIZJn38pVQn-2drotationangles2d platformer2.5dTue, 14 Apr 2020 14:26:39 GMTKie789Angle of bones to read the same as the inspector.
http://answers.unity.com/questions/1717824/angle-of-bones-to-read-the-same-as-the-inspector.html
I'm having problems getting the angle to read the same as the inspector. See the two attached pictures. The 2 pictures should show the same angle because they are the same angle, but they show different numbers that don't mach up to what is in the inspector angle for X. thanks in advance for your help.
[1]: /storage/temp/156514-2-pic.jpg
public class HelpMe : MonoBehaviour
{
public float angle;
public Transform getTransform;
void Update()
{
angle = Vector3.Angle(getTransform.position, transform.position);
Debug.Log(angle);
}quaternionangleboneanglesangleaxisMon, 13 Apr 2020 00:46:19 GMTitisiericCalculating the time it takes an object to rotate towards a moving target.
http://answers.unity.com/questions/1717272/calculating-the-time-it-takes-an-object-to-rotate.html
Hi all. I'm working on a 2D space game, but have hit a block with a maths problem which is a bit beyond me. I think this is solvable with a bit of trigonometry, but there might be a vector based solution too. I've searched for existing questions like this but haven't found anything i can apply. Thanks to anyone who takes the time to look at this for me - I'm hoping it will either be a fun challenge for people or so trivial that they won't mind helping!
Also, sorry if my notation is really bad. I've tried my best but I'm a music grad!
------------
The problem:
------------
A space ship is travelling on a 2D plane with a fixed velocity on the y axis.
The ship is rotating towards a fixed target point, at a known angular velocity (**ω**). I need to calculate the time (**t**) at which the ship is facing towards the target.
![alt text][1]
My attempt so far:
------------------
I have attempted to solve this with a bit of trigonometry, but I'm stumped on solving the final equations.
I'm using two functions:
**Δa** = the change in angle **a** between the ship and the target due to the ships rotation
**Δb** = the change in angle **b** between the ship and the target due to the ships velocity
The desired time **t** occurs when these two angles are equal: **a – b = 0**
I've calculated these functions as shown below.
Putting it all together, I need to solve the final equation for **t**. All other variables are known, but i don't have the maths skills to do this - hopefully it's not impossible :/
![alt text][2]
Thank you so much if you've even read this far.
[1]: /storage/temp/156382-spaceship-problem.png
[2]: /storage/temp/156388-equations.pngmovementanglesequationSat, 11 Apr 2020 14:01:59 GMTunity_UcbdUw2vhw0YHwUsing ProjectOnPlane to slide around adjacent edges
http://answers.unity.com/questions/1716405/using-projectonplane-to-slide-around-adjacent-edge.html
I'm using three raycasts to find the edge directly in front of my characterController capsule and store the normal:
void Update()
{
forwardRay = transform.position + transform.forward * 0.4f;
RaycastHit hitInfo = default(RaycastHit);
var raycast = Physics.Raycast(forwardRay, Vector3.down, out hitInfo, Mathf.Infinity, 1);
if (raycast)
{
edgeVector = Vector3.zero;
}
else
{
RaycastHit hitInfo1 = default(RaycastHit);
var raycast1 = Physics.Raycast(transform.position, Vector3.down, out hitInfo1, Mathf.Infinity, 1);
if (raycast1)
{
ground = hitInfo1.point;
RaycastHit hitInfo1 = default(RaycastHit);
var raycast2 = Physics.Raycast(new Vector3(forwardRay.x, ground.y + -0.02f, forwardRay.z), new Vector3((-transform.forward).x, Of, (-transform.forward).z), out hitInfol, Mathf.Infinity, 1);
if (raycast2)
{
edgeVector = hitInfo2.normal;
}
}
}
}
}
I then use ProjectOnPlane to ensure the characterController slides along the edge instead of just stopping dead in it's tracks:
GetComponent<CharacterController>().Move(Vector3.ProjectOnPlane(Quaternion.Euler(transform.eulerangles) * new Vector3(0f, gravity, currentSpeed), edgeVector) * Time.deltatime);
The trouble is, it doesn't handle adjacent corners at all and just falls off, since the raycast is only finding the edge normal directly in front of the capsule. Here you can see the red ray is my forward vector in worldspace, and it fires back from there (pink ray) towards the height of the ground beneath my capsule (blue ray): https://gfycat.com/delectableslipperygosling
Is it possible to find the next normal in the direction I'm moving, or better yet, wrap the ProjectOnPLane vector around the nearest normal in it's projected direction? Otherwise, I'm just doing this the wrong way?movementvector3normalsanglestrigonometryThu, 09 Apr 2020 09:56:12 GMTZebbilocalEulerAngles.x changes when the angle is close to -90 in the inspector
http://answers.unity.com/questions/1715889/localeuleranglesx-changes-when-the-angle-is-close.html
I need to read the angle of the knee joint but the problem is the (eulerAngX) value is not a linear relationship with the X angle in the inspector? I think the (eulerAngX) will change depending on how close it is to -90 in the inspector. (see the two attached pictures)
I need to read the angle of the knee joint to use in a robotic application you can see the YouTube video here to understand why I need to know the angle
https://www.youtube.com/watch?v=odWTkAmW1LA&t=5s
I can't seem to get my little brain to figure this problem out. Thanks in advance for your help.
public class HelpMe : MonoBehaviour
{
public float eulerAngX;
// Update is called once per frame
void Update()
{
eulerAngX = transform.localEulerAngles.x;
Debug.Log(eulerAngX);
}inspectorquaternioneuleranglesanglesTue, 07 Apr 2020 23:25:46 GMTitisiericFinding the x and y of Mathf.Atan2 after converted to degrees
http://answers.unity.com/questions/1715847/finding-the-x-and-y-of-mathfatan2-after-converted.html
Hello I'm trying to figure out how solve the x and y of Math.Atan2 after it is calculated and converted into a Degree using Mathf.Rad2Deg since I want to add a small change in the angle like 15 degrees or so which can be changable. I am mainly trying to implement this so I can have a 2d platformer directional shooter that shoots multiple bullets at once for my enemies to add more difficulty to the game
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public float y;
public float x;
public class PointAndShoot : MonoBehaviour
{
void FixedUpdate() {
float rotationZ = Mathf.Atan2(y, x) * Mathf.Rad2Deg;
//Want to figure out if its possible to add or subtract degrees from rotationZ and figure out what the
//x and y are in that degree angle
}
}anglesangle adjustTue, 07 Apr 2020 20:06:03 GMTScruffman10How To Calcutale New Position and Angle On The Line Objects
http://answers.unity.com/questions/1706804/how-to-calcutale-new-position-and-angle-on-the-lin.html
Hello to everyone. How can I position the object between two points so that when I move the points the object rests on the line. I made the angular calculation of the object, but I could not find what code to write about its position. please help me. 2 picture added commend. please look at pictures
The codes I wrote for the angle:
public GameObject node1, node2;
Vector3 dir1 = (node1.transform.position - node2.transform.position);
float atan2_1 = Mathf.Atan2(dir1.y, dir1.x);
transform.rotation = Quaternion.Euler(0f, 0f, atan2_1 * Mathf.Rad2Deg);mathfanglespositionsWed, 11 Mar 2020 18:12:04 GMTdirilikerhan355How to calculate internal angles of a mesh triangle?
http://answers.unity.com/questions/1704153/how-to-calculate-internal-angles-of-a-mesh-triangl.html
Hi Guys!
I'm trying to find the internal angles a, b and c of the triangle in the picture below. The red points form a triangle of a mesh.
I know the Vector3 positions of the red points and the normal of the triangle, but I don't know how to work out the angles between these points. How do I do this?
My triangle is below:
![alt text][1]
[1]: /storage/temp/153497-vla396goa6k41.pngmeshanglestrianglesMon, 02 Mar 2020 02:57:26 GMTIrishSenthilRotation from another object
http://answers.unity.com/questions/1701294/rotation-from-another-object.html
I am trying to get one object's rotation relative to another object, in euler angles as a degree value between (0 to 180) or (0 to -180). Ultimately just need the Vector3.y axis.
_
If the camera was looking directly towards the object it would give a 0 deg, and if you were looking directly away in the opposite direction it would give 180.
_
I am not trying to rotate any of the objects, just need to log this value.
_
Any help would be appreciated, thanks!rotationvector3anglesWed, 19 Feb 2020 17:39:48 GMTStrixie13Rotation in an if statement
http://answers.unity.com/questions/1698739/rotation-in-an-if-statement-1.html
I am fairly new to Unity and c# so please excuse my incompetence...
I am trying to **add torque to my game object if the (based on the transform UI) angle is greater than say 35 degrees** and also the corresponding negative degree. I have come to understand that the UI does not correspond with the angle values used in code, but it is the only basis I have.
I tried looking up how to do this and all I got was (for me) incomprehensible stuff about quaternions and Euler angles, but for the moment I don't have time to learn that in-depth, and I really just need to know what code to put in.
![alt text][1]
[1]: /storage/temp/152590-z35.pngrotationprogrammingif-statementsanglesMon, 10 Feb 2020 17:30:39 GMTDeltaScorchHow do I rotate using a negative angle value?,How to get the negative angle of an object?
http://answers.unity.com/questions/1693936/how-do-i-rotate-using-a-negative-angle-valuehow-to.html
I'm making a game where the player can rotate a platform. However, I don't want the player to be able to rotate the platform completely around. To prevent this I attempted to add if statements that would check the current value of the platforms angle, and if the angle was more or less than a specific angle it would continue to rotate when a specific key is being pressed. I understand that a negative angle isn't technically a thing but Unity's transform inspector shows a negative angle rather than passing 180 degrees. Is there a way to call that number rather than a number from 360? If not then might someone have an alternate suggestion on how to proceed with my goal?
Here's an example of the code I'm using.
void Update()
{
if (Input.GetKey(KeyCode.W))
{
if (gameObject.transform.rotation.eulerAngles.x < 20)
{
transform.Rotate(0.5f, 0, 0);
}
}
if (Input.GetKey(KeyCode.S))
{
if (gameObject.transform.rotation.eulerAngles.x > -20)
{
transform.Rotate(-0.5f, 0, 0);
}
}
}rotationrotaterotate objectanglesSat, 25 Jan 2020 16:22:11 GMTunity_KY4G73RefSj9BAGetting a forward angle for a throw.
http://answers.unity.com/questions/1692074/getting-a-forward-angle-for-a-throw.html
Hey, I'm trying to use this script to send obj1 forward based on special_obj's transform.forward, however no matter what special_obj's forward is, obj1 still only goes straight.
The original script came from here (modified slightly as my task is different):
https://forum.unity.com/threads/how-to-calculate-force-needed-to-jump-towards-target-point.372288/
float initialAngle = 10;
float gravity = Physics.gravity.magnitude;
float angle = initialAngle * Mathf.Deg2Rad;
// Positions of this object and the target on the same plane
Vector3 opos = new Vector3(obj1.position.x, 0, obj1.position.z);
Vector3 tpos = new Vector3(obj2.position.x, 0, obj2.position.z);
// Planar distance between objects
float distance = Vector3.Distance(tpos, opos);
// Distance along the y axis between objects
float yOffset = 0;
float initialVelocity = (1 / Mathf.Cos(angle)) * Mathf.Sqrt((0.5f * gravity * Mathf.Pow(distance, 2)) / (distance * Mathf.Tan(angle) + yOffset));
Vector3 velocity = new Vector3(0, initialVelocity * Mathf.Sin(angle), initialVelocity * Mathf.Cos(angle));
// Rotate our velocity to match the direction between the two objects
float angleBetweenObjects = Vector3.Angle(Vector3.forward, tpos - opos);
Vector3 targetDir = obj2.position - obj1.position;
//angleBetweenObjects = Vector3.SignedAngle(targetDir, transform.forward, Vector3.down);
angleBetweenObjects = Vector3.SignedAngle(targetDir, special_obj.forward, Vector3.down);
Vector3 finalVelocity = Quaternion.AngleAxis(angleBetweenObjects, Vector3.up) * velocity;
rb.AddForce(finalVelocity * rb.mass, ForceMode.Impulse);
The code will send obj1 however forward obj2 is, but even when obj2 is to it's left or behind, obj1 still goes Vector3.forward (the correct distance) rather than special_obj's transform.forward.
I even tried replacing every Vector3.direction with special_obj.forward and the result was the same.
Thanks in advance.anglesSat, 18 Jan 2020 08:26:45 GMT$$anonymous$$Rotate a 2d object based on velocity
http://answers.unity.com/questions/1685604/rotate-a-2d-object-based-on-velocity.html
Hello everyone I am pretty new to using unity and making games,
I am creating a worms type game and I have an object being shot based on the arrow angle.
![alt text][1]
[1]: https://i.gyazo.com/c1435bc837e722a86f6e26ff2d1bd812.png
Once the object is shot I want it to be rotated to look real as if the tip of the object is going down first. How could I go about doing this? I tried using this code once the object's Y velocity was going negative.
public class AirStrike : MonoBehaviour
{
public float spellSpeed = 8f;
public Vector3 targetAngle = new Vector3(0, 0, -121);
private Vector3 currentAngle;
// Start is called before the first frame update
void Start()
{
currentAngle = transform.eulerAngles;
}
// Update is called once per frame
void Update()
{
Debug.Log(GetComponent<Rigidbody2D>().velocity.y);
if (GetComponent<Rigidbody2D>().velocity.y <= 0)
{
currentAngle = new Vector3(
Mathf.LerpAngle(currentAngle.x, targetAngle.x, Time.deltaTime),
Mathf.LerpAngle(currentAngle.y, targetAngle.y, Time.deltaTime),
Mathf.LerpAngle(currentAngle.z, targetAngle.z, Time.deltaTime)
);
transform.eulerAngles = currentAngle;
}
}
}
Thanks for your help in advance :)anglesangularvelocityThu, 19 Dec 2019 00:44:47 GMTihearcolorsLookAt formula in Vector3
http://answers.unity.com/questions/1682784/lookat-formula-in-vector3.html
I need to get the Euler angles between two 3D points(Vector3) without using Quaternion.LookRotation. Is it possible? If yes - is there a precise formula to use?vector3lookatanglesSat, 07 Dec 2019 01:05:54 GMTGreatCornHow to detect when an object is within an arc?
http://answers.unity.com/questions/1677082/how-to-detect-when-an-object-is-within-an-arc.html
I'm having an issue trying to detect an object within an arc. What I'm trying to do is, after setting a minimum and maximum angle, detect an object that falls within that range. When I put in angle values like -60 degrees to 60 degrees, it works fine. When I put in a value that's 180 degrees (-90 to 90), my calculated Forward vector gets set to 0 (because I'm calculating a vector between the 2 angles), and when it's greater than 180 degrees, the detection becomes flipped.
Below are examples.
**Red Lines** = Detection Arc.
**Green Line** = Forward Axis.
**Cyan Line** = Detected Target.
![alt text][1]
----------
And here is the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MountedTurret : MonoBehaviour
{
[System.Serializable]
public class Turret
{
[SerializeField]
Vector3 _localPosition;
[SerializeField]
float _angleMin = -90;
[SerializeField]
float _angleMax = 90;
public float Range = 10f;
public float AngleMin(Transform t)
{
return _angleMin + t.eulerAngles.y;
}
public float AngleMax(Transform t)
{
return _angleMax + t.eulerAngles.y;
}
public Vector3 Position(Transform t)
{
return t.position + _localPosition;
}
public Vector3 Forward(Transform t)
{
var position = Position(t);
float aMin = AngleMin(t);
float aMax = AngleMax(t);
Vector3 vMin = new Vector3(Mathf.Sin(aMin * Mathf.Deg2Rad), 0, Mathf.Cos(aMin * Mathf.Deg2Rad));
Vector3 vMax = new Vector3(Mathf.Sin(aMax * Mathf.Deg2Rad), 0, Mathf.Cos(aMax * Mathf.Deg2Rad));
return ((vMin + vMax) * 0.5f).normalized;
}
public bool IsInRange(Transform t, Vector3 point)
{
var position = Position(t);
float dist = Vector3.Distance(position, point);
if(dist <= Range)
{
var direction = point - position;
float angle = Vector3.Angle(Forward(t), direction);
if(angle >= AngleMin(t) && angle <= AngleMax(t))
{
return true;
}
}
return false;
}
}
public Ship ship;
public Turret[] turrets;
public Transform test;
public void OnDrawGizmos()
{
const int segments = 5;
List<Vector2> arcPoints = new List<Vector2>();
float angle;
float arcLength;
Vector3 position;
foreach (Turret t in turrets)
{
position = t.Position(transform);
Gizmos.color = Color.green;
Debug.Log("My Forward is: " + t.Forward(transform));
Gizmos.DrawRay(position, t.Forward(transform) * t.Range);
angle = t.AngleMin(transform);
arcLength = t.AngleMax(transform) - angle;
for (int i = 0; i <= segments; i++)
{
float x = Mathf.Sin(Mathf.Deg2Rad * angle) * t.Range;
float y = Mathf.Cos(Mathf.Deg2Rad * angle) * t.Range;
arcPoints.Add(new Vector2(x, y));
angle += (arcLength / segments);
}
//TODO Draw the arc
Gizmos.color = Color.red;
var arcPos = new Vector3(position.x + arcPoints[0].x, position.y, position.z + arcPoints[0].y);
var prevPos = arcPos;
Gizmos.DrawLine(position, arcPos);
//TODO For
for(int i = 0; i < arcPoints.Count; ++i)
{
arcPos = new Vector3(position.x + arcPoints[i].x, position.y, position.z + arcPoints[i].y);
Gizmos.DrawLine(prevPos, arcPos);
prevPos = arcPos;
}
arcPos = new Vector3(position.x + arcPoints[arcPoints.Count - 1].x, position.y, position.z + arcPoints[arcPoints.Count - 1].y);
Gizmos.DrawLine(position, arcPos);
}
}
// Update is called once per frame
void Update()
{
foreach (Turret t in turrets)
{
if(t.IsInRange(transform, test.position))
{
Debug.DrawLine(t.Position(transform), test.position, Color.cyan);
}
}
}
}
[1]: /storage/temp/148525-arcbug.pngvector3mathdetectionanglesarcSun, 10 Nov 2019 00:10:17 GMTVRKeithSignedAngle returning wrong angles
http://answers.unity.com/questions/1673982/signedangle-returning-wrong-angles.html
In my code I have 2 points that my NPC navigates between in a 2D space. I use SignedAngle to get degrees the character should face (the angle between the point they are at and the point they are going to) and then use that to set their rotation. The angles are consistently incorrect for some reason. For example, even if both points are at the same x or y position, the angle won't be straight.
Here is my code:
`nextPoint = (curPoint + 1) % points.Length;`
`movementToNextPoint = new Vector2((points[nextPoint].position.x - transform.position.x) / timeBetweenPoints, (points[nextPoint].position.y - transform.position.y) / timeBetweenPoints);`
`degreeFacing = Vector3.SignedAngle(transform.position, points[nextPoint].position - transform.position, Vector3.forward);`
`transform.rotation = Quaternion.Euler(0, 0, degreeFacing);`
`curPoint = nextPoint;`
Is there anything wrong with this code? I'm really not sure what's wrong here, because the code seems to work on the first run but starts being incorrect afterwards. Thank you.vector3angleanglesThu, 24 Oct 2019 16:33:54 GMTmicpap25Rotate object in only one axis to face tha camera
http://answers.unity.com/questions/1669889/rotate-object-in-only-one-axis-to-face-tha-camera.html
Hello smart people!
Imagine a RTS game or something like this (with prespective camera from above with a little inclination). As the title says, i need to rotate an image, which is over the "ground" plane so its always facing the camera, so can only change the Z rotation component. But i dont want that image to rotate in any axis to face it, i want that always to be parallel to ground plane.
Look at the image below: I know how to get the position of the camera over the ground (B pos), its "projection", but im having problems to get how to rotate the image so its always "seen correctly" from the camera. I know is something about cos or sin but i con't get the correct formula.
anybody can help?
Thaanks!
![alt text][1]
[1]: /storage/temp/147054-rottoproject.jpgrotationanglesprojectionSat, 05 Oct 2019 11:27:46 GMTtormentoarmagedoomEuler angles clamping issue
http://answers.unity.com/questions/1661136/euler-angles-clamping-issue.html
I'm trying to clamp my player rotation to limitate it's view range. For 'y' axis it rotates the player, and for 'x' axis it rotates the camera.
I already have a method that clamp angles but my problem cames when I try to clamp 'y' axis dynamically. Let me explain it. First here is the method:
float ClampAngle(float angle, float min, float max)
{
if (angle < 0f) { angle = 360 + angle; }
if (angle > 180f) { return Mathf.Max(angle, 360 + min); }
return Mathf.Min(angle, max);
}
and how I implement that for the camera rotation:
camRot = myCam.transform.eulerAngles + new Vector3(-v, 0, 0);
camRot.x = ClampAngle(camRot.x, -maxCameraRot, maxCameraRot);
myCam.transform.eulerAngles = camRot;
It works fine and it clamps rotation from -90 to 90. But now I want to clamp player rotation too when press a button. Problem here is that player rotation vary when you move, so it's not that easy like clamp between -90 and 90.
I need to store actual rotation first, then substract 90 for the minimum and add 90 for the maximum. Something like this:
pjRot = transform.eulerAngles + new Vector3(0, h, 0);
pjRot.y = ClampAngle(pjRot.y, actualRot - 90, actualRot + 90);
transform.eulerAngles = pjRot;
It only works well when players rotation is 0, but if it's orientated to the left, right or any other direction it get's a little crazy.
I have been trying to look other posts or make it by myself, but i can not achive what i want.
Let me know if i'm doing it wrong or if I need another method.
Thanksrotationclampanglesmethodsclamped rotationTue, 27 Aug 2019 20:14:56 GMTJankaroHow to make player move the way the joystick is moving [Example Shown]
http://answers.unity.com/questions/1649583/how-to-make-player-move-the-way-the-joystick-is-mo.html
Im trying to make a fangame, but having trouble moving character like in the example, I looked through every post there was like my problem, but iim still not having any luck, I tried many times to work it through myself, but nothing worked, cause there was multiple errors and multiple things i did not want happening, if anyone can help, can you please help me with this situation. Thank you![alt text][1]
[1]: /storage/temp/143093-7f8b26ca-2aaf-4cdd-95b5-c5a3e30d2d07.pngrotationmovementcontrolleranglesThu, 18 Jul 2019 02:20:35 GMTTheMinecraftersruleSomething degrees
http://answers.unity.com/questions/1644926/something-degrees.html
Hey, sorry for the vague title, i really didn't know what to call this, also sorry for asking this many questions suddenly, im having a lot of trouble with angles recently and just wanted to get it over with.
The problem im facing now is that i have an arrow that points towards the cursor, but i need to only have this arrow rotate towards the cursor if its within an angle threshold, as an example if this threshold is 180 degrees, the arrow will always point in some direction to the right of the player. I have tried a lot of different aproaches, but im really bad at all this rotation and direction stuff. I just tried out vector2.angle but it calculates the angle with the world center 0, 0, 0 as the third value, i can't use that because my player moves around the scene.
Again sorry for asking a lot of questions recently and thanks!scripting problemdirectionanglesMon, 01 Jul 2019 17:01:16 GMT$$anonymous$$Rotate on one axis and check if angle is inside desired range
http://answers.unity.com/questions/1644888/rotate-on-one-axis-and-check-if-angle-is-inside-de.html
Hey, so i have been searching around for a long while for a solution, but i can't seem to find any way to solve this problem.
I have a script in a 2d sidescroller that makes an arrow which is a child of my player point towards my cursor over time with slerp. This is working but has one not desired effect and that is when i rotate my player 180 degrees on x to flip him, the arrow also flips and then rotates back with lerp, i need a way to only rotate it on one axis, and leave the other completely untouched, im using sprites so rotating them on any other axises makes things look wrong.
The other problem im facing is i need a way to detect if this arrow is within 2 angles, lets say 0 and 90 (the upper right part of the game), i haven't even found a way to get started at this, i don't get really get quaternions and am in general having a really hard time working with rotations.
I don't know if my explenation makes any sense but if it does and you have an answer, ill be grateful thanks.rotationscripting problemquaternionanglesMon, 01 Jul 2019 14:18:42 GMT$$anonymous$$Setting Vector3.angle between two gameObjects
http://answers.unity.com/questions/1642690/setting-vector3angle-between-two-gameobjects.html
So here is the question: I am able to get an angle between two gameObjects by using Vector3.angle
public Transform target;
void Update()
{
Vector3 targetDir = target.position - transform.position;
float angle = Vector3.Angle(targetDir, transform.forward);
}
but the real problem is that I want to set this angle to another two gameObjects which are at different positions and angles in world space...........
Thank You
(I am sorry but i was not able to upload images because i am getting a disgusting error in unity answers which says - Error parsing the uploaded file.)vector3gameobjectscoordinatesanglesFri, 21 Jun 2019 21:36:38 GMTChinmay_GawandeHow to get the angle between two objects with regard to a face side
http://answers.unity.com/questions/1634025/how-to-get-the-angle-between-two-objects-with-rega.html
Hi, I'm trying to get the relative angle between two gameObjects with regard to the "front" of the searching object (the object sending the raycast). The object starts at rotation (0,0,0), and with my current code (pasted below), it works fine as long as the searching object is always facing in that one direction. I believe the problem is with my use of Vector3.Forward, seeing as this is a set vector, and thus will always be facing towards (0,0,1). I just don't know what to replace it with to get a Vector3.Forward local effect. I tried adding transform.rotation.eulerAngles.y of the searching object to the targAngleFromForward, but then I need to subtract the y from... somewhere. I am rather confused and would appreciate any help offered.
![alt text][1]
This is being used for an enemy's line of sight against the player object in a stealth game.
[1]: /storage/temp/138671-capture.pngc#anglesvector3.angleWed, 22 May 2019 15:45:28 GMTMadboyJamesCalculate launch angle based on launch direction
http://answers.unity.com/questions/1633663/calculation-launch-angle-based-on-launch-direction.html
I'm working with a setup like this:
![alt text][1]
[1]: /storage/temp/138588-vectors.jpg
Where the vectors all start at transform.position and end as follows:
- Black: transform.position + HandlePosition
- Blue: transform.position + Vector2.right
- White: transform.position - HandlePosition.normalized
The idea is that i can move the red handle around to change the White vector (the launch direction of the object).
Now what I would like to get is the angle between the White and Blue vectors.
I want to get this angle so that I can calculate the trajectory of the object and display a trajectory line.
**Edit:**
Given the example shown on the picture, I would expect an angle of about 45 degrees.mathanglevectoranglescalculationsTue, 21 May 2019 16:46:58 GMTMalyglutDetect 2D FLIPS on the Z Axis
http://answers.unity.com/questions/1626333/detect-2d-flips-on-the-z-axis.html
Hi,
So I have this 2D POGO, a stick basically, which hops around. How do I detect if it does a flip between hops?
Optionally, i would like to detect if it is a front/back flip and also if it was a single/double/triple/ etc.
I'm not sure what I have to do, I tried subtracting the last rotation from the current one and adding them. I get strange results and I don't know how to do this.
Thanks!2danglesflipsSat, 27 Apr 2019 10:17:49 GMTJeezkerHow Do I accurately rotate a player 180 degrees about the Z axis?
http://answers.unity.com/questions/1626266/how-do-i-accurately-rotate-a-player-180-degrees-ab.html
So I am working on a gravity altering game that has forced me to better understand how angles work, although I am still struggling. In my game, I want to give the player the ability to flip gravity on demand. (Gravity is manually coded in, it is just a force being constantly applied to vector3.down). However, my issue isn't with gravity, it is with accurately rotating the player 180 degrees. I also have to keep in mind that I plan on the player being able to walk on walls, meaning their rotation may not be strictly 0, 0, 0 or 0, 0, 180 (My current rotation function rotates the player along the Z axis). Basically, if the player was in a cube, the player could be standing on any surface within the cube. But not any slanted surfaces: all surfaces the player walks on are in iterations of 90 degrees. I have code currently to rotate the player, but it does not work accurately. Here is the code:
void Update()
{
if (Input.GetButtonDown("Flip"))
{
StartCoroutine(Rotate(rb.rotation * Quaternion.Euler(0, 0, 180)));
}
}
IEnumerator Rotate(Quaternion target)
{
yield return null;
while (Vector3.Angle(rb.rotation.eulerAngles.normalized, target.eulerAngles.normalized) != 0f)
{
rb.MoveRotation(Quaternion.Slerp(rb.rotation, target, .5f));
yield return null;
}
}
So when I call Rotate, I pass in the current rotation already rotated 180 degrees around the Z axis, I just have to get to that point. Then I use the IEnumerator to continue to rotate until the angle between the current rotation and our target rotation is zero (Supposedly). Each time it isn't, use MoveRotation and Slerp to get closer, (this way the movement is more smooth). And it "almost" works. I suspect that Vector3.Angle is not totally accurate, because it always stops rotating barely before its target, with a few decimal points off. I tried adding normalized to the vectors being passed in, and I tried using Quaternion.Angle as well, but nothing seemed to fix the issue. I get the feeling that I should be approaching the problem in a completely different manner, but am not sure. Any help is much appreciated.rotationvector3quaternionanglesSat, 27 Apr 2019 02:31:45 GMTOdd-Awter