Version: Unity 6 (6000.0)
LanguageEnglish
  • C#

Vector3.Cross

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

public static Vector3 Cross(Vector3 lhs, Vector3 rhs);

Description

Cross Product of two vectors.

The cross product of two vectors results in a third vector which is perpendicular to the two input vectors. The result's magnitude is equal to the magnitudes of the two inputs multiplied together and then multiplied by the sine of the angle between the inputs. You can determine the direction of the result vector using the "left hand rule".


The left hand rule applied to Cross(a, b).

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { // Get the normal to a triangle from the three corner points a, b, and o, where o is the origin point of vectors a and b. Vector3 GetNormal(Vector3 a, Vector3 b, Vector3 o) { // Find vectors corresponding to two of the sides of the triangle. Vector3 side1 = a - o; Vector3 side2 = b - o;

// Cross the vectors to get a perpendicular vector, then normalize it. This is the Result vector in the drawing above. return Vector3.Cross(side1, side2).normalized; } }