Reputation: 3499
I want to get a vertex and store it in a variable. Then I want to keep updating the position, rotation and translation. Ik know I can just add up the position of the object to the position of the vertex to get the new vertex position. But I don't know how to do this with the scale and rotation. Does anyone know?
using UnityEngine;
using System.Collections;
public class FollowVertex : MonoBehaviour {
public Transform testSphere;
public Transform indicator;
void Update()
{
indicator.position = GetVertex();
}
Vector3 GetVertex()
{
Mesh TMesh = testSphere.GetComponent<MeshFilter>().mesh;
Vector3 Tvertex = TMesh.vertices[1];
return Tvertex + testSphere.position ; // + the rotation, scale and translation of "testSphere"
}
}
Thanks in advance!
Edit 1:
I think I can modify this RotateAround funtion for the rotation.
function RotateVertexAround(center: Vector3, axis: Vector3, angle: float){
var pos: Vector3 = transform.position;
var rot: Quaternion = Quaternion.AngleAxis(angle, axis); // get the desired rotation
var dir: Vector3 = pos - center; // find current direction relative to center
dir = rot * dir; // rotate the direction
transform.position = center + dir; // define new position
// rotate object to keep looking at the center:
var myRot: Quaternion = transform.rotation;
transform.rotation *= Quaternion.Inverse(myRot) * rot * myRot;
}
Now the Only thing I need to know is how to do the scale, can I do that with a matrix?
Upvotes: 0
Views: 1385
Reputation: 20028
You should be able to do that via the TransformPoint()
method, which transforms a vertex from local to world space.
i.e.
Vector3 GetVertex()
{
Mesh TMesh = testSphere.GetComponent<MeshFilter>().mesh;
Vector3 Tvertex = TMesh.vertices[1];
return testSphere.TransformPoint(Tvertex);
}
Upvotes: 3