Esempio n. 1
0
    public Direction DirectionAfterSteer(SteerDirection steer)
    {
        // Debug.Log("Input Steer enum: " + (int) steer);
        int       compassOffset = this.Id + (int)steer;
        Direction newDirection  = Direction.Compass[compassOffset];

        return(newDirection);
    }
Esempio n. 2
0
 public void DoSteer(SteerDirection steer)
 {
     if (SteerPointsRemaining == 0)
     {
         Facing = Facing.DirectionAfterSteer(steer);
         ResetSteerPoints();
         OnObjectSteered(Facing);
     }
 }
Esempio n. 3
0
        public void Setup()
        {
            targets = new Vector3[] { new Vector3(0, 0, 10) };

            scaled      = false;
            position    = new Vector3(0, 0, 0);
            range       = 11;
            weight      = 1;
            angle       = 90;
            invertScale = 0;

            axis = RotationAxis.YAxis;

            _weights = new float[] { 0f, 0f, 0f, 0f };

            direction = SteerDirection.ATTRACT;
        }
Esempio n. 4
0
        public void ZAxis()
        {
            axis    = RotationAxis.ZAxis;
            targets = new Vector3[] { new Vector3(0, 10, 0) };

            NativeArray <Vector3> targetPositions = new NativeArray <Vector3>(targets, Allocator.Temp);
            NativeArray <float>   Weights         = new NativeArray <float>(_weights, Allocator.Temp);

            SteerDirection direction = SteerDirection.ATTRACT;

            DotToVecJob job = new DotToVecJob()
            {
                targets     = targetPositions,
                scaled      = scaled,
                my_position = position,
                range       = range,
                weight      = weight,
                angle       = angle,
                invertScale = invertScale,
                axis        = axis,
                Weights     = Weights,
                direction   = direction
            };

            // compute
            job.Execute();

            // check result
            float[] expected = { 1f, 0f, -1f, 0f };

            Assert.AreEqual(expected[0], Weights[0], TestUtilities.DOTPRODTOLERANCE);
            Assert.AreEqual(expected[1], Weights[1], TestUtilities.DOTPRODTOLERANCE);
            Assert.AreEqual(expected[2], Weights[2], TestUtilities.DOTPRODTOLERANCE);
            Assert.AreEqual(expected[3], Weights[3], TestUtilities.DOTPRODTOLERANCE);

            targetPositions.Dispose();
            Weights.Dispose();
        }
Esempio n. 5
0
    //=====================================================
    //
    //  ##   ##  #####   ####      ###    ######  #####
    //  ##   ##  ##  ##  ##  ##   ## ##     ##    ##
    //  ##   ##  #####   ##  ##  ##   ##    ##    #####
    //  ##   ##  ##      ##  ##  #######    ##    ##
    //   #####   ##      ####    ##   ##    ##    #####
    //
    //=====================================================

    void FixedUpdate()
    {
        if (freeze)
        {
            return;
        }

        isGrounded = checkGrounded();

        if (false)
        {
            decelerate = Input.GetKey("s") ? true : false;
            if (Input.GetKey("a"))
            {
                steer = SteerDirection.Left;
            }
            else if (Input.GetKey("d"))
            {
                steer = SteerDirection.Right;
            }
            else
            {
                steer = SteerDirection.Neutral;
            }
            if (Input.GetKey("space"))
            {
                jump = JumpStatus.Jumping;
            }
        }

        //
        // ─── ACCELERATION ────────────────────────────────────────────────
        //

        if (decelerate)
        {
            currentVelocity -= decelerationRate;
        }
        else if (accelerate)
        {
            currentVelocity += accelerationRate;
        }

        currentVelocity = Mathf.Clamp(currentVelocity, initialVelocity, maxVelocity);
        level.transform.Translate(new Vector3(0, 0, -currentVelocity * Time.deltaTime));

        // ─────────────────────────────────────────────────────────────────


        //
        // ─── STEERING ────────────────────────────────────────────────────
        //

        if (steer == SteerDirection.Left)
        {
            currentSteering -= steeringRate;
            currentSteering  = Mathf.Clamp(currentSteering, -maxSteering, initialSteering);
        }
        else if (steer == SteerDirection.Right)
        {
            currentSteering += steeringRate;
            currentSteering  = Mathf.Clamp(currentSteering, initialSteering, maxSteering);
        }
        else
        {
            if (currentSteering < 0)
            {
                currentSteering += steeringReturnRate;
                currentSteering  = Mathf.Clamp(currentSteering, -maxSteering, initialSteering);
            }
            else if (currentSteering > 0)
            {
                currentSteering -= steeringReturnRate;
                currentSteering  = Mathf.Clamp(currentSteering, initialSteering, maxSteering);
            }
        }

        transform.Translate(Vector3.right * currentSteering * Time.deltaTime);

        // ─────────────────────────────────────────────────────────────────


        //
        // ─── JUMP ────────────────────────────────────────────────────────
        //

        // if (jump == JumpStatus.Jumping) {
        //  currentJumpHeight = transform.position.y - groundHeight;
        //  if (currentJumpHeight+jumpStrength*Time.deltaTime <= maxJumpHeight*jumps && jumps <= maxJumps) {
        //      currentJumpSpeed += jumpStrength;
        //      currentJumpSpeed = Mathf.Clamp(currentJumpSpeed, initialJumpSpeed, maxJumpSpeed);
        //  } else {
        //      jump = JumpStatus.Falling;
        //  }
        // } else if (jump == JumpStatus.Falling) {
        //  currentJumpSpeed = 0;
        //  if (isGrounded) {
        //      jump = JumpStatus.Idle;
        //  } else {
        //      currentJumpSpeed -= gravity;
        //  }
        // } else {
        //  jumps = 0;
        //  groundHeight = transform.position.y;
        // }

        if (jump == JumpStatus.Jumping)
        {
            currentJumpHeight = transform.position.y - groundHeight;
            if (currentJumpHeight + rb.velocity.y * Time.deltaTime <= maxJumpHeight * maxJumps && jumps <= maxJumps)
            {
                rb.velocity = Vector3.zero;
                rb.AddForce(0, jumpStrength * Time.deltaTime, 0, ForceMode.Impulse);
            }
            else
            {
                jump = JumpStatus.Falling;
            }
        }
        else if (jump == JumpStatus.Falling)
        {
            if (isGrounded)
            {
                jump = JumpStatus.Idle;
            }
            else
            {
                groundHeight = -1000;
            }
        }
        else
        {
            jumps        = 0;
            groundHeight = transform.position.y;
        }

        if (!isGrounded)
        {
            if (jump != JumpStatus.Jumping)
            {
                // jump = JumpStatus.Falling;
                rb.AddForce(0, gravity, 0, ForceMode.Force);
            }
        }

        // ─────────────────────────────────────────────────────────────────
    }