A plane that goes through two points and is parallel to player.transform.forward

115 views Asked by At

I've got a player with a sword and the two points on a target are from OnTriggerEnter and OnTriggerExit. Then I want to create a slicing plane that is parallel to player.transform.forward - it can be vertical, horizontal or on an angle (parallel to the player forward - which is always horizontal).

To define the plane I need its normal/up vector and one of the two points and it is infinite. So I'd like code for the plane's normal based on position1, position2, and player.transform.forward.

2

There are 2 answers

0
Luke Wenke On BEST ANSWER

Based on LoïcLeGrosFrère I did this: (EzySlice also has a Plane class)

UnityEngine.Plane plane = new UnityEngine.Plane(sliceStartPos, sliceEndPos, playerPos);

SlicedHull hull = objectToSlice.Slice(sliceStartPos, plane.normal, crossMat);

An alternative:

public Vector3 GetPlaneNormal(Vector3 a, Vector3 b, Vector3 c)
{
    return Vector3.Normalize(Vector3.Cross(b - a, c - a));
}
Vector3 planeNormal = GetPlaneNormal(sliceStartPos, sliceEndPos, playerPos);

SlicedHull hull = objectToSlice.Slice(sliceStartPos, planeNormal, crossMat);
0
LoïcLeGrosFrère On

If I understand what you want achieve (cut a target with the player sword ?), you can use your two points and the "shoulder" of the player to create your slicing plane with Plane.Set3Points