Question by
Sachato · Feb 20, 2021 at 08:53 PM ·
c#trigonometry
How to find the right position of Vector3 using trigonometry
Hello,
I have problems with calculating point using trigonometry... I know it's more math problem instead of coding, but can anybody help me with this topic?
Lets look at code
using UnityEngine;
public class Test : MonoBehaviour
{
public Transform p1;
public Transform p2;
void Update()
{
Debug.DrawLine(transform.position, p1.position);
Debug.DrawLine(transform.position, p2.position);
Vector3 difference1 = transform.position - p1.position;
Vector3 difference2 = transform.position - p2.position;
float angle = Vector3.SignedAngle(difference1, difference2, transform.up);
float a = angle * Mathf.PI / 180;
Vector3 p3 = p2.position;
p3.x = Mathf.Sin(a) * difference2.magnitude;
p3.z = Mathf.Cos(a) * difference2.magnitude;
}
}
Vector im trying to find is kind of reflection via my line from transform.position
to p1.position
, i mean i want to find the Vector that have the same angle as point p2
have between p1
, but in opposite side of my p1
line.
How can i do this? My p3
Vector that im calculating is located in some completely weird position. Can somebody tell me how to deal with trigonometry like this?
unity-quesion.png
(8.3 kB)
Comment