示例#1
0
    public void AgentRespawn()
    {
        if (explosion != null)
        {
            Instantiate(explosion, transform.position, Quaternion.identity);
        }

        rb.velocity        = Vector3.zero;
        rb.angularVelocity = Vector3.zero;

        // Ищем предыдущий чекпоинт
        Vector3 previousAgentCheckPoint;

        if (currentCheckPointInd - 1 < 0)
        {
            previousAgentCheckPoint = agentCheckPoints[agentCheckPoints.Length - 1].position;
        }
        else
        {
            previousAgentCheckPoint = agentCheckPoints[currentCheckPointInd - 1].position;
        }

        // Вычисляем новую позицию для машины
        PointOnLine respawnPoint  = new PointOnLine();                                                                                // Точка ближайшая точка на прямой между текущим и предыдущим чекопоинтом
        Vector3     requiredPoint = respawnPoint.GetPointOnLine(previousAgentCheckPoint, currentAgentCheckPoint, transform.position); // Получаем ближайшую точку на прямой между чекпоинтами

        requiredPoint     += placesForRespawn.placesForRespawn[respawnPlaceID];                                                       // Смещаем точку на свое заданное отклонение для респауна
        transform.position = requiredPoint + 20 * Vector3.up;                                                                         // Максимально поднимаем точку над трассой чтобы пустить вниз луч и нащупать поверхность
        gameObject.layer   = LayerMask.NameToLayer("Ignore Raycast");                                                                 // Меняем слой чтобы агент не обнаружил сам себя

        if (Physics.Raycast(transform.position, Vector3.down, out RaycastHit hit, Mathf.Infinity, surfaceSearchMask))                 // Пускаем вниз луч, ищем поверхность
        {
            transform.position = hit.point + distanceToGround;
            //Debug.Log("Найдено пересечение в точке: " + hit.point + " " + hit.collider.name);
        }
        public CharacterJoint3D(IWorld world, IBody3D body1, IBody3D body2, TSVector position, TSVector hingeAxis) : base((World)world)
        {
            RigidBody rigid1 = (RigidBody)body1;
            RigidBody rigid2 = (RigidBody)body2;

            fixedAngle  = new FixedAngle(rigid1, rigid2);
            pointOnLine = new PointOnLine(rigid1, rigid2, rigid1.position, rigid2.position);

            firstBody            = body1;
            secondBody           = body2;
            hingeA               = hingeAxis;
            worldPointConstraint = new PointOnPoint[2];
            hingeAxis           *= FP.Half;
            TSVector anchor = position;

            TSVector.Add(ref anchor, ref hingeAxis, out anchor);
            TSVector anchor2 = position;

            TSVector.Subtract(ref anchor2, ref hingeAxis, out anchor2);
            worldPointConstraint[0] = new PointOnPoint((RigidBody)body1, (RigidBody)body2, anchor);
            worldPointConstraint[1] = new PointOnPoint((RigidBody)body2, (RigidBody)body1, anchor2);
            StateTracker.AddTracking(worldPointConstraint[0]);
            StateTracker.AddTracking(worldPointConstraint[1]);
            //UnityEngine.CharacterJoint;
            Activate();
        }
        public PrismaticJoint(World world, RigidBody body1, RigidBody body2, float minimumDistance, float maximumDistance)
            : base(world)
        {
            fixedAngle  = new FixedAngle(body1, body2);
            pointOnLine = new PointOnLine(body1, body2, body1.position, body2.position);

            minDistance          = new PointPointDistance(body1, body2, body1.position, body2.position);
            minDistance.Behavior = PointPointDistance.DistanceBehavior.LimitMinimumDistance;
            minDistance.Distance = minimumDistance;

            maxDistance          = new PointPointDistance(body1, body2, body1.position, body2.position);
            maxDistance.Behavior = PointPointDistance.DistanceBehavior.LimitMaximumDistance;
            maxDistance.Distance = maximumDistance;
        }
示例#4
0
        public PrismaticJoint(World world, RigidBody body1, RigidBody body2, float minimumDistance, float maximumDistance)
            : base(world)
        {
            FixedAngleConstraint  = new FixedAngle(body1, body2);
            PointOnLineConstraint = new PointOnLine(body1, body2, body1.position, body2.position);

            MinimumDistanceConstraint = new PointPointDistance(body1, body2, body1.position, body2.position)
            {
                Behavior = PointPointDistance.DistanceBehavior.LimitMinimumDistance,
                Distance = minimumDistance
            };

            MaximumDistanceConstraint = new PointPointDistance(body1, body2, body1.position, body2.position)
            {
                Behavior = PointPointDistance.DistanceBehavior.LimitMaximumDistance,
                Distance = maximumDistance
            };
        }
示例#5
0
        public PrismaticJoint3D(IWorld world, IBody3D body1, IBody3D body2, FP minimumDistance, FP maximumDistance)
            : base((World)world)
        {
            //fixedAngle = new FixedAngle((RigidBody)body1, (RigidBody)body2);
            pointOnLine = new PointOnLine((RigidBody)body1, (RigidBody)body2, ((RigidBody)body1).position, ((RigidBody)body2).position);

            //minDistance = new PointPointDistance((RigidBody)body1, (RigidBody)body2, ((RigidBody)body1).position, ((RigidBody)body2).position);
            //minDistance.Behavior = PointPointDistance.DistanceBehavior.LimitMinimumDistance;
            //minDistance.Distance = minimumDistance;

            //maxDistance = new PointPointDistance((RigidBody)body1, (RigidBody)body2, ((RigidBody)body1).position, ((RigidBody)body2).position);
            //maxDistance.Behavior = PointPointDistance.DistanceBehavior.LimitMaximumDistance;
            //maxDistance.Distance = maximumDistance;

            //StateTracker.AddTracking(fixedAngle);
            StateTracker.AddTracking(pointOnLine);
            //StateTracker.AddTracking(minDistance);
            //StateTracker.AddTracking(maxDistance);

            Activate();
        }
示例#6
0
        private void CreatePointOnLineJoint()
        {
            JVector  lineStartPointBody1;
            Vector3D tempVector = ArrayExtensions.GetWithDefault <PropertyType, Vector3D>(Properties,
                                                                                          PropertyType.LineStartPointBody);

            JitterDatatypesMapping.Convert(ref tempVector, out lineStartPointBody1);
            JVector pointBody2;

            tempVector = ArrayExtensions.GetWithDefault <PropertyType, Vector3D>(Properties,
                                                                                 PropertyType.PointBody);
            JitterDatatypesMapping.Convert(ref tempVector, out pointBody2);
            if (RigidBodyB != null)
            {
                Constraint = new PointOnLine(RigidBodyA, RigidBodyB, lineStartPointBody1, pointBody2);
            }
            else
            {
                Logger.Warning("You're trying to create PointOnLine with second " +
                               "body at null.Maybe you should create SingleBodyPointOnLine.");
            }
        }
 public PrismaticJoint(World world, RigidBody body1, RigidBody body2, Vector3 pointOnBody1, Vector3 pointOnBody2, float maximumDistance, float minimumDistance)
     : base(world)
 {
     fixedAngle  = new FixedAngle(body1, body2);
     pointOnLine = new PointOnLine(body1, body2, pointOnBody1, pointOnBody2);
 }
 public PrismaticJoint(World world, RigidBody body1, RigidBody body2, Vector3 pointOnBody1, Vector3 pointOnBody2)
     : base(world)
 {
     fixedAngle  = new FixedAngle(body1, body2);
     pointOnLine = new PointOnLine(body1, body2, pointOnBody1, pointOnBody2);
 }
 public PrismaticJoint(World world, RigidBody body1, RigidBody body2)
     : base(world)
 {
     fixedAngle  = new FixedAngle(body1, body2);
     pointOnLine = new PointOnLine(body1, body2, body1.position, body2.position);
 }
示例#10
0
 public PrismaticJoint(World world, RigidBody body1, RigidBody body2, JVector pointOnBody1, JVector pointOnBody2, float maximumDistance, float minimumDistance)
     : base(world)
 {
     FixedAngleConstraint  = new FixedAngle(body1, body2);
     PointOnLineConstraint = new PointOnLine(body1, body2, pointOnBody1, pointOnBody2);
 }
 public PrismaticJoint3D(World world, RigidBody body1, RigidBody body2, FPVector pointOnBody1, FPVector pointOnBody2, FP maximumDistance, FP minimumDistance)
     : base(world)
 {
     fixedAngle  = new FixedAngle(body1, body2);
     pointOnLine = new PointOnLine(body1, body2, pointOnBody1, pointOnBody2);
 }
        public Mesh_PrimitiveMode(List <string> imageList) : base(imageList)
        {
            modelGroupName       = ModelGroupName.Mesh_PrimitiveMode;
            onlyBinaryProperties = false;
            noPrerequisite       = false;

            Runtime.Image figureIndices = new Runtime.Image
            {
                Uri = imageList.Find(e => e.Contains("Indices"))
            };
            Runtime.Image figurePointsIndices = new Runtime.Image
            {
                Uri = imageList.Find(e => e.Contains("Indices_Points"))
            };
            //Runtime.Image normalTexture = new Runtime.Image
            //{
            //    Uri = textures.Find(e => e.Contains("Normal_Plane"))
            //};
            //usedTextures.Add(normalTexture);
            usedFigures.Add(figureIndices);
            usedFigures.Add(figurePointsIndices);

            List <Vector3> noIndicesPositionsTriangles = new List <Vector3>()
            {
                new Vector3(-0.5f, -0.5f, 0.0f),
                new Vector3(0.5f, -0.5f, 0.0f),
                new Vector3(0.5f, 0.5f, 0.0f),
                new Vector3(-0.5f, -0.5f, 0.0f),
                new Vector3(0.5f, 0.5f, 0.0f),
                new Vector3(-0.5f, 0.5f, 0.0f),
            };
            List <Vector3> noIndicesPositionsLines = new List <Vector3>()
            {
                new Vector3(0.5f, -0.5f, 0.0f),
                new Vector3(-0.5f, -0.5f, 0.0f),
                new Vector3(-0.5f, -0.5f, 0.0f),
                new Vector3(-0.5f, 0.5f, 0.0f),
                new Vector3(-0.5f, 0.5f, 0.0f),
                new Vector3(0.5f, 0.5f, 0.0f),
                new Vector3(0.5f, 0.5f, 0.0f),
                new Vector3(0.5f, -0.5f, 0.0f),
            };
            List <Vector3> noIndicesPositionsLineloopFan = new List <Vector3>()
            {
                new Vector3(0.5f, -0.5f, 0.0f),
                new Vector3(0.5f, 0.5f, 0.0f),
                new Vector3(-0.5f, 0.5f, 0.0f),
                new Vector3(-0.5f, -0.5f, 0.0f),
            };

            // Make a list of verticies for points with 1024 values
            List <Vector3> noIndicesPositionsPoints = new List <Vector3>();
            List <Vector3> cornerPoints             = new List <Vector3>()
            {
                new Vector3(0.5f, -0.5f, 0.0f),
                new Vector3(-0.5f, -0.5f, 0.0f),
                new Vector3(-0.5f, 0.5f, 0.0f),
                new Vector3(0.5f, 0.5f, 0.0f),
                new Vector3(0.5f, -0.5f, 0.0f)
            };

            for (int corner = 0; corner < 4; corner++)
            {
                for (int x = 256; x > 0; x--)
                {
                    Vector3 startPoint     = cornerPoints[corner];
                    Vector3 endPoint       = cornerPoints[corner + 1];
                    float   fractionOfLine = (float)x / 256f;
                    noIndicesPositionsPoints.Add(PointOnLine.FindPoint(startPoint, endPoint, fractionOfLine));
                }
            }

            List <Vector3> noIndicesPositionsLineStrip = new List <Vector3>()
            {
                new Vector3(0.5f, -0.5f, 0.0f),
                new Vector3(0.5f, 0.5f, 0.0f),
                new Vector3(-0.5f, 0.5f, 0.0f),
                new Vector3(-0.5f, -0.5f, 0.0f),
                new Vector3(0.5f, -0.5f, 0.0f),
            };
            List <Vector3> noIndicesPositionsTrianglestrip = new List <Vector3>()
            {
                new Vector3(0.5f, -0.5f, 0.0f),
                new Vector3(0.5f, 0.5f, 0.0f),
                new Vector3(-0.5f, -0.5f, 0.0f),
                new Vector3(-0.5f, 0.5f, 0.0f),
            };

            Runtime.GLTF defaultModel        = Common.SinglePlane(); // Only used to get the default indices
            List <int>   defaultModelIndices = new List <int>(defaultModel.Scenes[0].Nodes[0].Mesh.MeshPrimitives[0].Indices);
            List <int>   linesIndices        = new List <int>
            {
                0, 3, 3, 2, 2, 1, 1, 0,
            };
            List <int> lineloopFanIndices = new List <int>
            {
                0, 3, 2, 1,
            };
            List <int> linestripIndices = new List <int>
            {
                0, 3, 2, 1, 0,
            };
            List <int> trianglestripIndices = new List <int>
            {
                0, 3, 1, 2,
            };
            List <int> pointsIndices = new List <int>();

            for (int x = 0; x < noIndicesPositionsPoints.Count; x++)
            {
                pointsIndices.Add(x);
            }

            //List<Vector2> pointsTextureCoords = new List<Vector2>()
            //{
            //    new Vector2(1.0f, 1.0f),
            //    new Vector2(0.75f, 1.0f),
            //    new Vector2(0.5f, 1.0f),
            //    new Vector2(0.25f, 1.0f),
            //    new Vector2(0.0f, 1.0f),
            //    new Vector2(0.0f, 0.75f),
            //    new Vector2(0.0f, 0.5f),
            //    new Vector2(0.0f, 0.25f),
            //    new Vector2(0.0f, 0.0f),
            //    new Vector2(0.25f, 0.0f),
            //    new Vector2(0.5f, 0.0f),
            //    new Vector2(0.75f, 0.0f),
            //    new Vector2(1.0f, 0.0f),
            //    new Vector2(1.0f, 0.25f),
            //    new Vector2(1.0f, 0.5f),
            //    new Vector2(1.0f, 0.75f),
            //};
            //List<Vector2> linesTextureCoords = new List<Vector2>()
            //{
            //    new Vector2(1.0f, 1.0f),
            //    new Vector2(0.0f, 1.0f),
            //    new Vector2(0.0f, 1.0f),
            //    new Vector2(0.0f, 0.0f),
            //    new Vector2(0.0f, 0.0f),
            //    new Vector2(1.0f, 0.0f),
            //    new Vector2(1.0f, 0.0f),
            //    new Vector2(1.0f, 1.0f),
            //};
            //List<List<Vector2>> textureCoords = new List<List<Vector2>>()
            //{
            //    pointsTextureCoords,
            //    linesTextureCoords
            //};
            //List<Vector3> normalsPoints = new List<Vector3>();
            //List<Vector4> tangentsPoints = new List<Vector4>();
            //for (int x = 0; x < 16; x++)
            //{
            //    normalsPoints.Add(new Vector3(0.0f, 0.0f, 1.0f));
            //    tangentsPoints.Add(new Vector4(1.0f, 0.0f, 0.0f, 1.0f));
            //}
            //List<Vector3> normalsLines = new List<Vector3>();
            //List<Vector4> tangentsLines = new List<Vector4>();
            //for (int x = 0; x < 8; x++)
            //{
            //    normalsLines.Add(new Vector3(0.0f, 0.0f, 1.0f));
            //    tangentsLines.Add(new Vector4(1.0f, 0.0f, 0.0f, 1.0f));
            //}
            //List<List<Vector3>> normals = new List<List<Vector3>>()
            //{
            //    normalsPoints,
            //    normalsLines
            //};
            //List<List<Vector4>> tangents = new List<List<Vector4>>()
            //{
            //    tangentsPoints,
            //    tangentsLines
            //};

            properties = new List <Property>
            {
                new Property(Propertyname.Mode_Points, Runtime.MeshPrimitive.ModeEnum.POINTS, group: 1),
                new Property(Propertyname.Mode_Lines, Runtime.MeshPrimitive.ModeEnum.LINES, group: 1),
                new Property(Propertyname.Mode_Line_Loop, Runtime.MeshPrimitive.ModeEnum.LINE_LOOP, group: 1),
                new Property(Propertyname.Mode_Line_Strip, Runtime.MeshPrimitive.ModeEnum.LINE_STRIP, group: 1),
                new Property(Propertyname.Mode_Triangle_Strip, Runtime.MeshPrimitive.ModeEnum.TRIANGLE_STRIP, group: 1),
                new Property(Propertyname.Mode_Triangle_Fan, Runtime.MeshPrimitive.ModeEnum.TRIANGLE_FAN, group: 1),
                new Property(Propertyname.Mode_Triangles, Runtime.MeshPrimitive.ModeEnum.TRIANGLES, group: 1),
                new Property(Propertyname.IndicesValues_Points, "[0 - 1023]", Propertyname.Mode_Points, group: 2),
                new Property(Propertyname.IndicesValues_Lines, linesIndices, Propertyname.Mode_Lines, group: 2),
                new Property(Propertyname.IndicesValues_LineLoop, lineloopFanIndices, Propertyname.Mode_Line_Loop, group: 2),
                new Property(Propertyname.IndicesValues_LineStrip, linestripIndices, Propertyname.Mode_Line_Strip, group: 2),
                new Property(Propertyname.IndicesValues_TriangleStrip, trianglestripIndices, Propertyname.Mode_Triangle_Strip, group: 2),
                new Property(Propertyname.IndicesValues_TriangleFan, lineloopFanIndices, Propertyname.Mode_Triangle_Fan, group: 2),
                new Property(Propertyname.IndicesValues_Triangles, defaultModelIndices, Propertyname.Mode_Triangles, group: 2),
                new Property(Propertyname.IndicesValues_None, " ", group: 2),
                new Property(Propertyname.IndicesComponentType_Byte, Runtime.MeshPrimitive.IndexComponentTypeEnum.UNSIGNED_BYTE, group: 4),
                new Property(Propertyname.IndicesComponentType_Short, Runtime.MeshPrimitive.IndexComponentTypeEnum.UNSIGNED_SHORT, group: 4),
                new Property(Propertyname.IndicesComponentType_Int, Runtime.MeshPrimitive.IndexComponentTypeEnum.UNSIGNED_INT, group: 4),
                new Property(Propertyname.IndicesComponentType_None, " ", group: 4),
                //new Property(Propertyname.VertexUV0_Float, ":white_check_mark:", group:5),
                //new Property(Propertyname.VertexNormal, ":white_check_mark:"),
                //new Property(Propertyname.VertexTangent, ":white_check_mark:"),
                //new Property(Propertyname.NormalTexture, normalTexture),
            };
            specialProperties = new List <Property>
            {
                //new Property(Propertyname.VertexUV0_Float, textureCoords, group:5),
                //new Property(Propertyname.VertexNormal, normals),
                //new Property(Propertyname.VertexTangent, tangents),
                new Property(Propertyname.Mode_Points, noIndicesPositionsPoints, group: 1),
                new Property(Propertyname.Mode_Lines, noIndicesPositionsLines, group: 1),
                new Property(Propertyname.Mode_Line_Loop, noIndicesPositionsLineloopFan, group: 1),
                new Property(Propertyname.Mode_Line_Strip, noIndicesPositionsLineStrip, group: 1),
                new Property(Propertyname.Mode_Triangle_Strip, noIndicesPositionsTrianglestrip, group: 1),
                new Property(Propertyname.Mode_Triangle_Fan, noIndicesPositionsLineloopFan, group: 1),
                new Property(Propertyname.Mode_Triangles, noIndicesPositionsTriangles, group: 1),
                new Property(Propertyname.IndicesValues_Points, pointsIndices, Propertyname.Mode_Points, group: 2),
            };
            // Each mode with and without indices, and drop singles
            var defaultIndices = properties.Find(e => e.name == Propertyname.IndicesComponentType_Int);
            var noIndicesType  = properties.Find(e => e.name == Propertyname.IndicesComponentType_None);
            var noIndicesValue = properties.Find(e => e.name == Propertyname.IndicesValues_None);

            foreach (var property in properties)
            {
                if (property.propertyGroup == 1)
                {
                    var IndicesValues = properties.Find(e => e.prerequisite == property.name);
                    specialCombos.Add(ComboHelper.CustomComboCreation(
                                          property,
                                          defaultIndices,
                                          IndicesValues));
                    specialCombos.Add(ComboHelper.CustomComboCreation(
                                          property,
                                          noIndicesValue,
                                          noIndicesType));
                }
                removeCombos.Add(ComboHelper.CustomComboCreation(
                                     property));
            }

            var valueTriangles = properties.Find(e => e.name == Propertyname.IndicesValues_Triangles);
            var modeTriangles  = properties.Find(e => e.name == Propertyname.Mode_Triangles);
            var modePoints     = properties.Find(e => e.name == Propertyname.Mode_Points);
            var modeLines      = properties.Find(e => e.name == Propertyname.Mode_Lines);
            var typeByte       = properties.Find(e => e.name == Propertyname.IndicesComponentType_Byte);
            var typeShort      = properties.Find(e => e.name == Propertyname.IndicesComponentType_Short);
            var vertexUV       = properties.Find(e => e.name == Propertyname.VertexUV0_Float);

            //var normal = properties.Find(e => e.name == Propertyname.VertexNormal);
            //var tangent = properties.Find(e => e.name == Propertyname.VertexTangent);
            //var normalTex = properties.Find(e => e.name == Propertyname.NormalTexture);
            specialCombos.Add(new List <Property>()
            {
                valueTriangles,
                typeByte,
                modeTriangles
            });
            specialCombos.Add(new List <Property>()
            {
                valueTriangles,
                typeShort,
                modeTriangles
            });
            //specialCombos.Add(new List<Property>()
            //{
            //    modePoints,
            //    noIndicesValue,
            //    noIndicesType,
            //    vertexUV,
            //    normal
            //});
            //specialCombos.Add(new List<Property>()
            //{
            //    modeLines,
            //    noIndicesValue,
            //    noIndicesType,
            //    vertexUV,
            //    normal
            //});
            //specialCombos.Add(new List<Property>()
            //{
            //    modeLines,
            //    noIndicesValue,
            //    noIndicesType,
            //    vertexUV,
            //    normal,
            //    tangent,
            //    normalTex
            //});
        }