// Update is called once per frame void Update() { Vector3[] TransformedVertices = new Vector3[ModelSpaceVertices.Length]; Vector3 ParentForward = EulerMaths.ForwardDirection(Parent.Transform.RotationEuler) * Distance; Matrix4by4 T = new Matrix4by4(new Vector3(1, 0, 0), new Vector3(0, 1, 0), new Vector3(0, 0, 1), new Vector3(ParentForward.x, ParentForward.y, ParentForward.z)); Matrix4by4 S = new Matrix4by4(new Vector3(1, 0, 0) * scale, new Vector3(0, 1, 0) * scale, new Vector3(0, 0, 1) * scale, new Vector3(0, 0, 0)); M2 = Parent.Transform.ReturnFinishedMatrix() * T * S; for (int i = 0; i < TransformedVertices.Length; i++) { TransformedVertices[i] = M2 * ModelSpaceVertices[i]; } MeshFilter MF = GetComponent <MeshFilter>(); MF.mesh.vertices = TransformedVertices; MF.mesh.RecalculateNormals(); MF.mesh.RecalculateBounds(); }
// Update is called once per frame void Update() { Vector3[] TransformedVertices = new Vector3[ModelSpaceVertices.Length]; angle += Time.deltaTime * 1; Rotation *= new Quat(EulerMaths.DegtoRag(RotationSpeed), VectorMaths.VectorNormalised(new Vector3(0, 1, 0))); for (int i = 0; i < TransformedVertices.Length; i++) { Quat p = new Quat(ModelSpaceVertices[i]); Quat newp = ((Rotation * p) * Rotation.Inverse()); Vector3 newpos = newp.GetAxisAngle(); TransformedVertices[i] = newpos; } MeshFilter MF = GetComponent <MeshFilter>(); MF.mesh.vertices = TransformedVertices; MF.mesh.RecalculateNormals(); MF.mesh.RecalculateBounds(); }
void UpdateMovement() { if (MoveForward == true) //Forward state is defined { Rig.force = EulerMaths.EulerToDirection(Transform.RotationEuler) * speed * Time.deltaTime; //Work out the direction and apply thrust in that direction } else if (MoveBackward == true) { Rig.force = EulerMaths.EulerToDirection(Transform.RotationEuler) * -speed * Time.deltaTime; //the same but in reverse } if (MoveLeft == true) { Transform.RotationEuler = new Vector3(Transform.RotationEuler.x, Transform.RotationEuler.y - RotationSpeed * Time.deltaTime, Transform.RotationEuler.z); //Rotate in the left direction by the rotation speed } else if (MoveRight == true) { Transform.RotationEuler = new Vector3(Transform.RotationEuler.x, Transform.RotationEuler.y + RotationSpeed * Time.deltaTime, Transform.RotationEuler.z); } }
// Update is called once per frame void Update() { transform.position = ShipLocal.Transform.Position + EulerMaths.EulerToDirection(ShipLocal.Rig.velocity) * -CameraDistance; }