Exemplo n.º 1
0
        private void Start()
        {
            PosRot placement = CalcTargetPlacement();

            transform.position = placement.Position;
            transform.rotation = placement.Rotation;
        }
Exemplo n.º 2
0
        private void OnDrawGizmos()
        {
            Gizmos.color = Color.red;
            PosRot placement = CalcTargetPlacement();

            Gizmos.DrawLine(transform.position, placement.Position);

            Gizmos.matrix = Matrix4x4.TRS(placement.Position, placement.Rotation, Vector3.one);
            Gizmos.DrawCube(Vector3.zero, new Vector3(5, 1, 10));
            Gizmos.matrix = Matrix4x4.identity;
        }
Exemplo n.º 3
0
        private PosRot CalcTargetPlacement()
        {
            Ray        ray = new Ray(transform.position, transform.rotation * Vector3.down);
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit, 100, placementLayers.value))
            {
                PosRot placement = new PosRot();
                placement.Position = hit.point;

                Quaternion alongNormal = Quaternion.FromToRotation(Vector3.up, hit.normal);
                float      angle       = transform.rotation.eulerAngles.y;
                placement.Rotation = Quaternion.AngleAxis(angle, hit.normal) * alongNormal;

                return(placement);
            }
            return(new PosRot(transform.position, transform.rotation));
        }