示例#1
0
        override public void Think(Bodies.BaseBody body)
        {
            if (chaseTarget.constValue != null)
            {
                //IJump bodyJump = body as IJump;
                IMoveX          bodyMoveX  = body as IMoveX;
                IHaveDirections directions = body as IHaveDirections;

                if (bodyMoveX != null)
                {
                    if (body.transform.position.x - chaseTarget.constValue.position.x > 0)
                    {
                        bodyMoveX.MoveX(-1f);
                    }
                    else if (body.transform.position.x - chaseTarget.constValue.position.x < 0)
                    {
                        bodyMoveX.MoveX(1f);
                    }
                }


                if (directions != null)
                {
                    //Debug.Log(directions.forward);

                    Vector3 heading = chaseTarget.constValue.position - body.transform.position;
                    float   dot     = Vector3.Dot(heading, directions.forward);

                    Debug.Log(dot);
                    //Debug.Log(directions.right);
                }
            }
        }
示例#2
0
        override public void Think(Bodies.BaseBody body)
        {
            IJump  bodyJump  = body as IJump;
            IMoveX bodyMoveX = body as IMoveX;
            IMoveY bodyMoveY = body as IMoveY;

            if (bodyJump != null)
            {
                if (Input.GetButtonDown(jumpButtonName))
                {
                    bodyJump.JumpBegin();
                }
                else if (Input.GetButtonUp(jumpButtonName))
                {
                    bodyJump.JumpEnd();
                }
            }

            if (bodyMoveX != null)
            {
                bodyMoveX.MoveX(Input.GetAxis(xAxisName));
            }

            if (bodyMoveY != null)
            {
                bodyMoveY.MoveY(Input.GetAxis(yAxisName));
            }
        }
        public override void Think(BaseBody body)
        {
            IMoveX bodyMoveX = body as IMoveX;
            //IHaveDirections directions = body as IHaveDirections;

            Vector3 currentTarget;

            if (bodyMoveX != null)
            {
                if (body.Remember <bool>("goingToEnd"))
                {
                    currentTarget = body.Remember <Vector3>("patrolEnd");
                }
                else
                {
                    currentTarget = body.Remember <Vector3>("patrolStart");
                }

                if (Mathf.Abs(body.transform.position.x - currentTarget.x) <= moveDeadZone.constValue)
                {
                    //if(Vector3.Magnitude(body.transform.position - currentTarget) < moveDeadZone.constValue) {

                    Debug.Log("Switch Target");

                    if (body.Remember <bool>("goingToEnd"))
                    {
                        Debug.Log("Switch to Start");
                        body.Remember("goingToEnd", false);
                    }
                    else
                    {
                        Debug.Log("Switch to End");
                        body.Remember("goingToEnd", true);
                    }
                }


                if (body.transform.position.x - currentTarget.x > moveDeadZone.constValue)
                {
                    bodyMoveX.MoveX(-1f);
                }
                else if (body.transform.position.x - currentTarget.x < moveDeadZone.constValue)
                {
                    bodyMoveX.MoveX(1f);
                }

                Debug.Log(currentTarget);
            }

            //if(directions != null) {

            //	Vector3 heading = body.Remember<Vector3>("currentTarget") - body.transform.position;
            //	float dot = Vector3.Dot(heading, directions.forward);
            //}
        }
        protected virtual void Update()
        {
            IMoveX bodyMoveX = body as IMoveX;
            IMoveY bodyMoveY = body as IMoveY;
            IMoveZ bodyMoveZ = body as IMoveZ;
            ITwist bodyTwist = body as ITwist;
            IJump  bodyJump  = body as IJump;

            if (bodyJump != null)
            {
                if (Input.GetButtonDown(jumpButtonName))
                {
                    bodyJump.JumpBegin();
                }
                else if (Input.GetButtonUp(jumpButtonName))
                {
                    bodyJump.JumpEnd();
                }
            }

            if (bodyMoveX != null)
            {
                bodyMoveX.MoveX(Input.GetAxis(xAxisName));
            }

            if (bodyMoveY != null)
            {
                bodyMoveY.MoveY(Input.GetAxis(yAxisName));
            }

            if (bodyMoveZ != null)
            {
                if (Input.GetAxis(zAxisName) < 0f)
                {
                    int x = 1;
                    x += 1;
                }

                bodyMoveZ.MoveZ(Input.GetAxis(zAxisName));
            }

            if (bodyTwist != null)
            {
                bodyTwist.Twist(Input.GetAxis(twistAxisName) * Time.deltaTime * maxTwistSpeed);
            }
        }
        protected virtual void Update()
        {
            IMoveX bodyMoveX = body as IMoveX;
            IMoveY bodyMoveY = body as IMoveY;
            IMoveZ bodyMoveZ = body as IMoveZ;
            ITwist bodyTwist = body as ITwist;
            IJump  bodyJump  = body as IJump;

            // For the sake of following the target, we need to see if they're
            // distant from us. This is going to be a pretty dumb follow
            // function and doesn't care how high-up they are. Thus, we will
            // project both our position and the target's position onto the
            // same plane. Then any heigh-difference gets ignored.
            //
            // If needed, we could also calculate the height pretty easily.
            // Just take the difference of the actual positions with their
            // respective projected positions, and these are their heights
            // relative to the plane. With this knowledge, we could calculate
            // the height relative to one another.
            Vector3 currentProjectedPos = Vector3.ProjectOnPlane(transform.position, transform.up);
            Vector3 targetProjectedPos  = Vector3.ProjectOnPlane(target.position, transform.up);

            if ((targetProjectedPos - currentProjectedPos).sqrMagnitude > maxDist * maxDist)
            {
                if (bodyMoveZ != null)
                {
                    walkingSpeed = Mathf.Clamp01(walkingSpeed + Time.deltaTime);
                    bodyMoveZ.MoveZ(walkingSpeed);
                }

                if (bodyTwist != null)
                {
                    bodyTwist.TwistToward(target.position);
                }
            }
            else
            {
                walkingSpeed = 0f;
            }
        }