I want to rotate a plane towards a normal of 3 Vectors/Points
Hi! Im am trying to create a plane that is defined by 3 points, one of them you can reposition with your mouse. The other is calculated so that the 3 Points form a plane that is tangent to a cone.
I don't know how to create a plane that has those three points/Vectors (like this)
What I tried to do was get the normal of these three points (point v, point p, point t) and set the rotation of the plane to that normal pointing towards the top of the plane:
The result I get from this, is the plane switching between the intended rotation and reset rotation every frame. here is the whole code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TangentPlane : MonoBehaviour
{
//Point Vectors
public Vector3 tPoint;
public Vector3 vPoint;
public Vector3 pPoint;
private Vector3 sideA;
private Vector3 SideB;
public Vector3 planeNormal;
// Horizontal Plane
private GameObject TangentEquation;
private bool horizontalPlane;
private bool perfilTangent;
void Update()
{
//Horizontal Plane
TangentEquation = GameObject.FindGameObjectWithTag("Tangent");
horizontalPlane = TangentEquation.GetComponent<TangentEquation>().horizontalPlane;
perfilTangent = TangentEquation.GetComponent<TangentEquation>().perfilTangent;
//Points
tPoint = GameObject.FindGameObjectWithTag("Tangent").transform.position;
vPoint = GameObject.FindGameObjectWithTag("VPoint").transform.position;
pPoint = GameObject.FindGameObjectWithTag("P").transform.position;
// Establish the difference betwen points
sideA = tPoint - vPoint;
SideB = pPoint - vPoint;
//calculate the normal
planeNormal = (Vector3.Cross(sideA, SideB)).normalized;
transform.rotation = Quaternion.FromToRotation(transform.up, planeNormal);
if(Input.GetMouseButtonUp(0))
{
if (horizontalPlane == true)
{ }
else if (perfilTangent == true)
{ }
else
{
}
}
}
}
Blockquote
Answer by Sunatic · Apr 20, 2021 at 09:29 AM
If you edit this code transform.rotation = Quaternion.FromToRotation(transform.up, planeNormal);
For this transform.rotation = Quaternion.FromToRotation(transform.position, planeNormal);
You get the desired result :)
Your answer
![](https://koobas.hobune.stream/wayback/20220613032505im_/https://answers.unity.com/themes/thub/images/avi.jpg)