Example #1
0
        void Update()
        {
            walker.RespawnAtTriangle(701, angle, coords);
            walker.WriteToTransform(startMarker);

            float     distanceLeft = distance;
            const int kMaxSteps    = 16;
            int       i;

            for (i = 0; i < kMaxSteps && distanceLeft > 0; i++)
            {
                walker.StepUntilEdge(distanceLeft, out distanceLeft);
                walker.WriteToTransform(intersectionMarker);
            }
            steps = i;

            walker.DebugDrawAxes();
        }
Example #2
0
        public void SpawnNewFood()
        {
            GameObject food = UnityEngine.Object.Instantiate(foodPrefab);

            walker.RespawnRandomly();
            walker.WriteToTransform(food.transform);

            OnFoodSpawned?.Invoke(food);
        }
Example #3
0
        void Update()
        {
            // Rotate
            {
                if (joystick.isPressed)
                {
                    // Update target angle

                    Vector3 worldDirection = Camera.main.cameraToWorldMatrix
                                             .MultiplyVector(joystick.Direction);

                    /*Debug.DrawLine(transform.position, transform.position + worldDirection * 4,
                     *  Color.red, 0, false);*/

                    Vector2 surfaceDirection = walker.worldToSurface.MultiplyVector(worldDirection);
                    Vector3 pos = walker.SurfaceTransform_.localPosition;

                    /*walker.DrawLocalLine(pos, pos + (Vector3)surfaceDirection.normalized * 4,
                     *  Color.yellow);*/

                    targetAngle = surfaceDirection.GetAngle();
                }

                float currentAngle = walker.SurfaceTransform_.angle;

                // Debug draw

                /*{
                 *  Vector3 pos = walker.SurfaceTransform_.localPosition;
                 *
                 *  Vector2 currentDirection = MathUtils.AngleToDirection(currentAngle);
                 *  walker.DrawLocalLine(pos, pos + (Vector3)currentDirection * 4,
                 *      Color.magenta);
                 *
                 *  Vector2 targetDirection = MathUtils.AngleToDirection(targetAngle);
                 *  walker.DrawLocalLine(pos, pos + (Vector3)targetDirection * 4,
                 *      Color.cyan);
                 * }*/

                float step = rotationSpeed * Time.deltaTime;
                step = ApproachToAngle(targetAngle, currentAngle, step);
                walker.Rotate(step);
            }

            // Move
            {
                float distance = moveSpeed * Time.deltaTime;
                while (distance > 0)
                {
                    walker.StepUntilEdge(distance, out distance);
                }
            }

            walker.WriteToTransform(transform);
            transform.position += transform.up * offsetFromSurface;
        }