Esempio n. 1
0
 /**
  * @fn  void HandleJumpStateActivation(JUMP_STATE jumpState)
  * @brief   Handle jump state activation.
  * @author  Eagan
  * @date    10/21/2013
  * @param   jumpState   State of the jump.
  */
 void HandleJumpStateActivation(JUMP_STATE jumpState)
 {
     if (jumpState == JUMP_STATE.PENDING)
     {
         myVelocity.y = myJumpVelocity;
         jumpState = JUMP_STATE.ACTIVE;
     }
 }
Esempio n. 2
0
    // Update is called once per frame
    void Update()
    {
        if (!isInitialized)
        {
            return;
        }
        //kin.AddToGrammar("destroy");
        //Debug.Log(kin.GetLastRecoResult());
        // Check for lightning
        Vector3 rightHand     = kin.GetJointPos(KinectWrapper.Joints.HAND_RIGHT);
        Vector3 rightShoulder = kin.GetJointPos(KinectWrapper.Joints.SHOULDER_RIGHT);
        Vector3 rightVec      = rightHand - rightShoulder;

        rightVec.z = -1 * rightVec.z;
        if (rightVec.z / rightVec.magnitude > STATE_THRESHOLD)
        {
            rightArm = ARM_STATE.AS_POS_Z;
        }
        else if (rightVec.z / rightVec.magnitude < -STATE_THRESHOLD)
        {
            rightArm = ARM_STATE.AS_NEG_Z;
        }
        else if (rightVec.x / rightVec.magnitude < -STATE_THRESHOLD)
        {
            rightArm = ARM_STATE.AS_NEG_X;
        }
        else if (rightVec.x / rightVec.magnitude > STATE_THRESHOLD)
        {
            rightArm = ARM_STATE.AS_POS_X;
        }
        else if (rightVec.y / rightVec.magnitude < -STATE_THRESHOLD)
        {
            rightArm = ARM_STATE.AS_NEG_Y;
        }
        else if (rightVec.y / rightVec.magnitude > STATE_THRESHOLD)
        {
            rightArm = ARM_STATE.AS_POS_Y;
        }
        else
        {
            rightArm = ARM_STATE.AS_NONE;
        }



        Vector3 leftHand     = kin.GetJointPos(KinectWrapper.Joints.HAND_LEFT);
        Vector3 leftShoulder = kin.GetJointPos(KinectWrapper.Joints.SHOULDER_LEFT);
        Vector3 leftVec      = leftHand - leftShoulder;

        leftVec.z = -1 * leftVec.z;
        if (leftVec.z / leftVec.magnitude > STATE_THRESHOLD)
        {
            leftArm = ARM_STATE.AS_POS_Z;
        }
        else if (leftVec.z / leftVec.magnitude < -STATE_THRESHOLD)
        {
            leftArm = ARM_STATE.AS_NEG_Z;
        }
        else if (leftVec.x / leftVec.magnitude < -STATE_THRESHOLD)
        {
            leftArm = ARM_STATE.AS_NEG_X;
        }
        else if (leftVec.x / leftVec.magnitude > STATE_THRESHOLD)
        {
            leftArm = ARM_STATE.AS_POS_X;
        }
        else if (leftVec.y / leftVec.magnitude < -STATE_THRESHOLD)
        {
            leftArm = ARM_STATE.AS_NEG_Y;
        }
        else if (leftVec.y / leftVec.magnitude > STATE_THRESHOLD)
        {
            leftArm = ARM_STATE.AS_POS_Y;
        }
        else
        {
            leftArm = ARM_STATE.AS_NONE;
        }


        Vector3 rightfoot       = kin.GetJointPos(KinectWrapper.Joints.FOOT_RIGHT);
        Vector3 leftfoot        = kin.GetJointPos(KinectWrapper.Joints.FOOT_LEFT);
        float   DisBetweenFoots = rightfoot.z - leftfoot.z;
        float   DisToJump       = Mathf.Abs(leftfoot.y) - Mathf.Abs(rightfoot.y);

        if (DisBetweenFoots > LEG_THRESHOLD)
        {
            rightLeg = LEG_STATE.AS_BACKWORD;
        }
        else if (DisBetweenFoots < -LEG_THRESHOLD)
        {
            rightLeg = LEG_STATE.AS_FORWORD;;
        }
        else
        {
            rightLeg = LEG_STATE.AS_NONE;
        }

        if (DisToJump > 90)
        {
            rightLegJump = JUMP_STATE.AS_JUMP;
        }
        else
        {
            rightLegJump = JUMP_STATE.AS_NONE;
        }

        Vector3 headVec = kin.GetJointPos(KinectWrapper.Joints.HEAD);
        Vector3 kneeVec = kin.GetJointPos(KinectWrapper.Joints.KNEE_LEFT);
        float   DisBetweenHeadAndKnee = headVec.y - kneeVec.y;

        if (DisBetweenHeadAndKnee < DUCK_THRESHOLD)
        {
            headKneeLeft = DUCK_STATE.AS_DUCK;
        }
        else
        {
            headKneeLeft = DUCK_STATE.AS_NONE;
        }

        //Debug.Log(headKneeLeft + ": " + DisBetweenHeadAndKnee);
    }
Esempio n. 3
0
    // Update is called once per frame
    void Update()
    {
        //RaycastHit rayHit;
        //float stepMoveDistance = this.moveDistancePerSecond * Time.deltaTime;

        if (Input.GetKeyDown(KeyCode.UpArrow))
        {
            this.jumpState = JUMP_STATE.JUMPING_UP_FIXED;
            this.cumulativeCurrentJumpHeight = 0f;
            this.lastVel = this.jumpStartVel;
        }
        if (Input.GetKeyDown(KeyCode.DownArrow))
        {
            if (this.jumpState == JUMP_STATE.ON_GROUND)
            {
                // duck.  I guess I'll need to see how animating works with mesh colliders
            }
        }
        if (Input.GetKeyUp(KeyCode.UpArrow) && this.jumpState != JUMP_STATE.ON_GROUND && this.jumpState != JUMP_STATE.FALLING_DOWN)
        {
            this.jumpState = JUMP_STATE.FALLING_DOWN;
            this.lastVel /= this.jumpSpeedFactorOnJumpRelease;
        }
        if (Input.GetKey(KeyCode.LeftArrow))
        {
            //if (this.body.SweepTest(new Vector3(-1, 0, 0), out rayHit, stepMoveDistance))
            //{
            //    this.transform.Translate(new Vector3(-rayHit.distance + Utils.MOVE_PADDING, 0, 0));
            //}
            //else
            //{
            //    this.transform.Translate(new Vector3(-stepMoveDistance, 0, 0));
            //}
        }
        if (Input.GetKey(KeyCode.RightArrow))
        {
            //if (this.body.SweepTest(new Vector3(1, 0, 0), out rayHit, stepMoveDistance))
            //{
            //    this.transform.Translate(new Vector3(rayHit.distance - Utils.MOVE_PADDING, 0, 0));
            //}
            //else
            //{
            //    this.transform.Translate(new Vector3(stepMoveDistance, 0, 0));
            //}
        }
    }
Esempio n. 4
0
    void FixedUpdate()
    {
        // v = at
        // d = vt
        // d = at^2
        // d= v1t * (0.5)at^2

        // up movement
        float deltaUp = 0f;
        float lastVelBeforeUpdate = this.lastVel;
        RaycastHit rayHit;

        switch (this.jumpState)
        {
            case JUMP_STATE.JUMPING_UP_FIXED:
                if (this.cumulativeCurrentJumpHeight > this.minJumpClimb)
                {
                    this.jumpState = JUMP_STATE.JUMPING_UP_VAR;
                }
                break;
            case JUMP_STATE.JUMPING_UP_VAR:
                if (this.cumulativeCurrentJumpHeight > this.maxJumpClimb)
                {
                    this.jumpState = JUMP_STATE.FALLING_DOWN;
                    this.lastVel /= this.jumpSpeedFactorOnJumpRelease;
                }
                break;
        }

        switch (this.jumpState)
        {
            case JUMP_STATE.ON_GROUND:
                deltaUp = 0f;
                break;
            case JUMP_STATE.JUMPING_UP_FIXED:
                Debug.Log("111111");
                deltaUp = this.lastVel * Time.deltaTime + this.shortestJumpUpGrav * Time.deltaTime * Time.deltaTime / 2f;
                this.lastVel = deltaUp / Time.deltaTime;
                break;
            case JUMP_STATE.JUMPING_UP_VAR:
                Debug.Log("222222");
                deltaUp = this.lastVel * Time.deltaTime + this.maxJumpUpGrav * Time.deltaTime * Time.deltaTime / 2f;
                this.lastVel = deltaUp / Time.deltaTime;
                break;
            case JUMP_STATE.FALLING_DOWN:
                Debug.Log("333333");
                deltaUp = this.lastVel * Time.deltaTime + this.fallGrav * Time.deltaTime * Time.deltaTime / 2f;
                this.lastVel = deltaUp / Time.deltaTime;
                break;
        }

        if (lastVelBeforeUpdate > 0 && this.lastVel < 0)
        {
            // PUSH THIS F****R DOWN
            this.lastVel = this.downwardPush;
        }

        //Debug.Log("the delta up is: " + deltaUp);
        //Debug.Log("The position is: " + this.transform.position.y);

        //if (Input.GetKey(KeyCode.LeftArrow))
        //{
        //    if (this.body.SweepTest(new Vector3(-1, 0, 0), out rayHit, -this.maxRunSpeed * Time.deltaTime))
        //    {
        //        this.transform.Translate(new Vector3(-rayHit.distance + Utils.MOVE_PADDING, 0, 0));
        //    }
        //    else
        //    {
        //        this.transform.Translate(new Vector3(-this.maxRunSpeed * Time.deltaTime, 0, 0));
        //    }
        //}
        //if (Input.GetKey(KeyCode.RightArrow))
        //{
        //    if (this.body.SweepTest(new Vector3(1, 0, 0), out rayHit, this.maxRunSpeed * Time.deltaTime))
        //    {
        //        this.transform.Translate(new Vector3(rayHit.distance - Utils.MOVE_PADDING, 0, 0));
        //    }
        //    else
        //    {
        //        this.transform.Translate(new Vector3(this.maxRunSpeed * Time.deltaTime, 0, 0));
        //    }
        //}

        // vertical sweep
        if (this.body.SweepTest(new Vector3(0, 1, 0), out rayHit, deltaUp))
        {
            this.transform.Translate(new Vector3(0, rayHit.distance - Utils.MOVE_PADDING, 0));
            Debug.Log("There was a hit and I am moving: " + rayHit.distance);
            this.jumpState = JUMP_STATE.ON_GROUND;
        }
        else
        {
            this.transform.Translate(new Vector3(0, deltaUp, 0));
            this.cumulativeCurrentJumpHeight += deltaUp;
        }
    }
Esempio n. 5
0
 protected void JumpStart()
 {
     this.jumpState = JUMP_STATE.JUMPING_START;
     this.jumpTime = 0f;
     this.breakJump = false;
 }
Esempio n. 6
0
    protected void FixedUpdate()
    {
        // DEBUG STUFF
        string objectName = this.name;
        //Debug.Log();

        if (jumpState == JUMP_STATE.DISABLED)
            return;

        if (this.jumpState != JUMP_STATE.ON_GROUND)
        {
            this.jumpTime += Time.deltaTime;
        }

        // calculate every update because F**K YEAH
        float accelDown = -Mathf.Pow(this.terminalFallVel, 2f) / (2f * this.termFallVelHeight);

        // up movement
        float deltaUp = 0f;
        RaycastHit rayHit;

        float newVelocity = 0f;
        float accelUp;

        switch (this.jumpState)
        {
            case JUMP_STATE.ON_GROUND:
                deltaUp = 0f;
                break;
            case JUMP_STATE.JUMPING_START:
                accelUp = -2f * this.maxJumpHeight / this.maxJumpTime / this.maxJumpTime;
                newVelocity = (this.maxJumpHeight / this.maxJumpTime) - accelUp * this.maxJumpTime / 2f;
                deltaUp = newVelocity * Time.deltaTime;
                this.jumpState = JUMP_STATE.JUMPING_UP;
                break;
            case JUMP_STATE.JUMPING_UP:
                accelUp = -2f * this.maxJumpHeight / this.maxJumpTime / this.maxJumpTime;
                newVelocity = this.lastVel + accelUp * Time.deltaTime;
                deltaUp = newVelocity * Time.deltaTime;
                if (newVelocity < 0 || this.breakJump)
                {
                    this.jumpState = JUMP_STATE.FALLING_DOWN_ACCEL;
                    this.breakJump = false;
                }
                break;
            case JUMP_STATE.FALLING_DOWN_ACCEL:
                newVelocity = this.lastVel + accelDown * Time.deltaTime;
                if (newVelocity < this.terminalFallVel)
                {
                    newVelocity = this.terminalFallVel;
                    this.jumpState = JUMP_STATE.FALLING_DOWN_TERMINAL;
                }
                deltaUp = newVelocity * Time.deltaTime;
                break;
            case JUMP_STATE.FALLING_DOWN_TERMINAL:
                deltaUp = this.terminalFallVel * Time.deltaTime;
                break;
        }

        this.lastVel = newVelocity;

        float deltaSide = 0f;
        switch (this.runState)
        {
            case RUN_STATE_TEMP.STATIONARY:
                break;
            case RUN_STATE_TEMP.LEFT:
                deltaSide = this.walkSpeed * Time.deltaTime * -1;
                break;
            case RUN_STATE_TEMP.RIGHT:
                deltaSide = this.walkSpeed * Time.deltaTime;
                break;
        }

        // vertical sweep
        Vector3 movementVector = new Vector3(deltaSide, deltaUp, 0);
        Vector3 movementVectorNormalized = movementVector.normalized;
        float movementVectorMagnitude = movementVector.magnitude;
        if (this.body.SweepTest(movementVectorNormalized, out rayHit, movementVectorMagnitude))
        {
            onHitCollider(rayHit.collider);

            // there was a hit... okay, need to handle this!
            // move as far as we can along this vector and then figure out which direction we're blocked in
            this.transform.Translate(movementVectorNormalized * (rayHit.distance - Utils.MOVE_PADDING));

            // need to sweep the remainder of vertcal and horizonal movement
            Vector3 remainingVector = movementVectorNormalized * (movementVectorMagnitude - rayHit.distance);
            //if (this.body.SweepTest(new Vector3(remainingVector.x > 0 ? 1.0f : -1.0f, 0, 0), out rayHit, Mathf.Abs(remainingVector.x)))
            if (this.body.SweepTest(new Vector3(1, 0, 0), out rayHit, deltaSide) && !canDodge(rayHit.collider.gameObject))
            {
                //this.transform.Translate(new Vector3(rayHit.distance - Utils.MOVE_PADDING * deltaSide > 0 ? 1 : -1, 0, 0));
                float partialMoveXDist = rayHit.distance - Utils.MOVE_PADDING * Mathf.Sign(rayHit.distance);
                this.transform.Translate(new Vector3(partialMoveXDist, 0, 0));
                //if (remainingVector.x < 0)
                if (deltaSide < 0)
                    onHitLeft(rayHit.collider);
                else
                    onHitRight(rayHit.collider);

                Collider collidedActor = collidesWith (actors);
                if((collidedActor != null && !canDodge(collidedActor.gameObject)) || collidesWith(tiles))
                {
                     this.transform.Translate(new Vector3(-partialMoveXDist, 0, 0));
                }
            }
            else
            {
                //this.transform.Translate(new Vector3(remainingVector.x, 0, 0));
                this.transform.Translate(new Vector3(deltaSide, 0, 0));

                Collider collidedActor = collidesWith (actors);
                if((collidedActor != null && !canDodge(collidedActor.gameObject)) || collidesWith(tiles))
                {
                    this.transform.Translate(new Vector3(-deltaSide, 0, 0));
                }
            }

            //if (this.body.SweepTest(new Vector3(0, remainingVector.y > 0 ? 1.0f : -1.0f, 0), out rayHit, Mathf.Abs(remainingVector.y)))
            if (this.body.SweepTest(new Vector3(0, 1, 0), out rayHit, deltaUp) && !canDodge(rayHit.collider.gameObject))
            {
                float partialMoveYDist = rayHit.distance - Utils.MOVE_PADDING * Mathf.Sign(rayHit.distance);
                this.transform.Translate(new Vector3(0, partialMoveYDist, 0));
                if (deltaUp >= 0)
                {
                    this.jumpState = JUMP_STATE.FALLING_DOWN_ACCEL;
                    this.lastVel = 0f;
                }
                else
                {
                    this.jumpState = JUMP_STATE.ON_GROUND;
                }

                Collider collidedActor = collidesWith (actors);
                if((collidedActor != null && !canDodge(collidedActor.gameObject)) || collidesWith(tiles))
                {
                    this.transform.Translate(new Vector3(0, -partialMoveYDist, 0));
                    this.cumulativeCurrentJumpHeight -= partialMoveYDist;
                }
            }
            else
            {
                //this.transform.Translate(new Vector3(0, remainingVector.y, 0));
                this.transform.Translate(new Vector3(0, deltaUp, 0));
                //this.cumulativeCurrentJumpHeight += remainingVector.y;
                this.cumulativeCurrentJumpHeight += deltaUp;

                Collider collidedActor = collidesWith (actors);
                if((collidedActor != null && !canDodge(collidedActor.gameObject)) || collidesWith(tiles))
                {
                    this.transform.Translate(new Vector3(0, -remainingVector.y, 0));
                    this.cumulativeCurrentJumpHeight -= remainingVector.y;
                }
            }
        }
        else
        {
            if (this.jumpState == JUMP_STATE.ON_GROUND && !this.body.SweepTest(new Vector3(0, -1, 0), out rayHit, 0.1f))
            {
                this.jumpState = JUMP_STATE.FALLING_DOWN_ACCEL;
                this.lastVel = 0f;
            }
            this.transform.Translate(movementVector);
        }
    }
Esempio n. 7
0
 protected void DisableActor()
 {
     this.jumpState = JUMP_STATE.DISABLED;
 }
Esempio n. 8
0
    // Use this for initialization
    protected void Awake()
    {
        transform.position = transform.position + new Vector3(0.0f, 0.01f, 0.0f);

        if (terminalFallVel == 0.0f)
            jumpState = JUMP_STATE.ON_GROUND;

        Collider[] colliders = FindObjectsOfType(typeof(Collider)) as Collider[];
        foreach(Collider collider in colliders)
        {
            if(collider.gameObject != null && collider.gameObject.GetComponent<Actor>())
                this.actors.Add(collider);
            else
                this.tiles.Add(collider);
        }

        this.body = GetComponent<Rigidbody>();
        hasAnimations = runAnimationName.Length > 0 &&
            idleAnimationName.Length > 0 &&
            actionAnimationName.Length > 0 &&
            action2AnimationName.Length > 0 &&
            crouchIdleAnimationName.Length > 0 &&
            crouchMoveAnimationName.Length > 0 &&
            jumpAnimationName.Length > 0;
    }
    // Update is called once per frame
    void Update()
    {
        if (!isInitialized) return;
		//kin.AddToGrammar("destroy");
		//Debug.Log(kin.GetLastRecoResult());
        // Check for lightning
        Vector3 rightHand = kin.GetJointPos(KinectWrapper.Joints.HAND_RIGHT);
        Vector3 rightShoulder = kin.GetJointPos(KinectWrapper.Joints.SHOULDER_RIGHT);
        Vector3 rightVec = rightHand - rightShoulder;
        rightVec.z = -1 * rightVec.z;
        if (rightVec.z / rightVec.magnitude > STATE_THRESHOLD)
        {
            rightArm = ARM_STATE.AS_POS_Z;
        }
        else if (rightVec.z / rightVec.magnitude < -STATE_THRESHOLD)
        {
            rightArm = ARM_STATE.AS_NEG_Z;
        }
        else if (rightVec.x / rightVec.magnitude < -STATE_THRESHOLD)
        {
            rightArm = ARM_STATE.AS_NEG_X;
        }
        else if (rightVec.x / rightVec.magnitude > STATE_THRESHOLD)
        {
            rightArm = ARM_STATE.AS_POS_X;
        }
        else if (rightVec.y / rightVec.magnitude < -STATE_THRESHOLD)
        {
            rightArm = ARM_STATE.AS_NEG_Y;
        }
        else if (rightVec.y / rightVec.magnitude > STATE_THRESHOLD)
        {
            rightArm = ARM_STATE.AS_POS_Y;
        }
        else
        {
            rightArm = ARM_STATE.AS_NONE;
        }



        Vector3 leftHand = kin.GetJointPos(KinectWrapper.Joints.HAND_LEFT);
        Vector3 leftShoulder = kin.GetJointPos(KinectWrapper.Joints.SHOULDER_LEFT);
        Vector3 leftVec = leftHand - leftShoulder;
        leftVec.z = -1 * leftVec.z;
        if (leftVec.z / leftVec.magnitude > STATE_THRESHOLD)
        {
            leftArm = ARM_STATE.AS_POS_Z;
        }
        else if (leftVec.z / leftVec.magnitude < -STATE_THRESHOLD)
        {
            leftArm = ARM_STATE.AS_NEG_Z;
        }
        else if (leftVec.x / leftVec.magnitude < -STATE_THRESHOLD)
        {
            leftArm = ARM_STATE.AS_NEG_X;
        }
        else if (leftVec.x / leftVec.magnitude > STATE_THRESHOLD)
        {
            leftArm = ARM_STATE.AS_POS_X;
        }
        else if (leftVec.y / leftVec.magnitude < -STATE_THRESHOLD)
        {
            leftArm = ARM_STATE.AS_NEG_Y;
        }
        else if (leftVec.y / leftVec.magnitude > STATE_THRESHOLD)
        {
            leftArm = ARM_STATE.AS_POS_Y;
        }
        else
        {
            leftArm = ARM_STATE.AS_NONE;
        }
		
		
		Vector3 rightfoot = kin.GetJointPos(KinectWrapper.Joints.FOOT_RIGHT);
		Vector3 leftfoot = kin.GetJointPos(KinectWrapper.Joints.FOOT_LEFT);
		float DisBetweenFoots = rightfoot.z - leftfoot.z;
		float DisToJump = Mathf.Abs(leftfoot.y) - Mathf.Abs(rightfoot.y);
		if (DisBetweenFoots > LEG_THRESHOLD)
        {
            rightLeg = LEG_STATE.AS_BACKWORD;
        }
        else if (DisBetweenFoots < -LEG_THRESHOLD)
        {
            rightLeg = LEG_STATE.AS_FORWORD;;
        }
        else
        {
            rightLeg = LEG_STATE.AS_NONE;
        }
		
		if ( DisToJump > 90 )
		{
			rightLegJump = JUMP_STATE.AS_JUMP;
		} else {
			rightLegJump = JUMP_STATE.AS_NONE;
		}
		
		Vector3 headVec = kin.GetJointPos(KinectWrapper.Joints.HEAD);
		Vector3 kneeVec = kin.GetJointPos(KinectWrapper.Joints.KNEE_LEFT);
		float DisBetweenHeadAndKnee = headVec.y - kneeVec.y;
		
        if (DisBetweenHeadAndKnee < DUCK_THRESHOLD){
			headKneeLeft = DUCK_STATE.AS_DUCK;
		} else {
			headKneeLeft = DUCK_STATE.AS_NONE;
		}
		
		//Debug.Log(headKneeLeft + ": " + DisBetweenHeadAndKnee);
    }