Example #1
0
    /// <summary> Returns a unit vector representing the chosen movement axis. </summary>
    /// <param name="axis"></param>
    /// <returns></returns>
    public static Vector3 GetAxis(MovementAxis axis)
    {
        Vector3 res = Vector3.zero;

        res[(int)axis] = 1;
        return(res);
    }
Example #2
0
 public void setActiveAxes(MovementAxis activeAxes)
 {
     clearSelection();
     xAxisBox.Enabled = (activeAxes & MovementAxis.X) == MovementAxis.X;
     yAxisBox.Enabled = (activeAxes & MovementAxis.Y) == MovementAxis.Y;
     zAxisBox.Enabled = (activeAxes & MovementAxis.Z) == MovementAxis.Z;
 }
 public void setActivePlanes(MovementAxis axes, MovementPlane planes)
 {
     foreach (MovableObjectTools currentTools in movableObjects)
     {
         currentTools.setActiveAxes(axes);
         currentTools.setActivePlanes(planes);
     }
 }
Example #4
0
    //---------------------------------------------------------------------------------------------------------------------------------------
    //  Monobehaviour

    #region Monobehaviour

    void Awake()
    {
        this.isInteractable      = false;
        this.actualMoveDirection = this.moveDirection;
        this.SetMoveAxis(this.actualMoveDirection);
        for (int i = 0; i < this.handles.Count; i++)
        {
            this.handles[i].ConnectTo(this);
        }
    }
        public TurtleBot3JointInfo(JointType jointType, LinkType linkType, MovementType movementType, MovementAxis movementAxis, float minVal, float maxVal)
        {
            this.jointType = jointType;
//			this.jointName    = jointName;
            this.linkType     = linkType;
            this.movementType = movementType;
            this.movementAxis = movementAxis;
            this.minVal       = minVal;
            this.maxVal       = maxVal;
        }
Example #6
0
 protected bool CanPlayAnimation(MovementAxis movementAxis)
 {
     if (((controller.slots.physicsObject.IsOnSurface() && !canMoveVertically) || (canMoveVertically && movementAxis == MovementAxis.Horizontal)) && controller.StateID() != id && controller.currentState.id != JumpState.idString && controller.currentState.id != LadderState.idString && controller.currentState.id != CrouchState.idString)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Example #7
0
 /// <summary> Retrieve the index (x, y or z) of the movementAxis. </summary>
 /// <param name="axis"></param>
 /// <returns></returns>
 public static int AngleIndex(MovementAxis axis)
 {
     if (axis == MovementAxis.Y)
     {
         return(1);
     }
     if (axis == MovementAxis.Z)
     {
         return(2);
     }
     return(0);
 }
Example #8
0
    /// <summary> Retrieve a Vector3 representation of this dial's rotation axis. </summary>
    /// <param name="axis"></param>
    /// <returns></returns>
    public static Vector3 GetAxis(MovementAxis axis)
    {
        switch (axis)
        {
        case MovementAxis.X: return(new Vector3(1, 0, 0));

        case MovementAxis.Y: return(new Vector3(0, 1, 0));

        case MovementAxis.Z: return(new Vector3(0, 0, 1));
        }
        return(new Vector3(1, 0, 0));
    }
    /// <summary>
    /// Sets parameter values based on enemy settings
    /// </summary>
    private void SetValues()
    {
        if (enemySettings.MovementDirection != MovementAxis.NaN) //if enemy has direction
        {
            isMoving     = true;
            movementAxis = enemySettings.MovementDirection;
            moveSpeed    = enemySettings.MoveSpeed;
            moveDistance = enemySettings.MoveDistance;

            if (movementAxis == MovementAxis.HORIZONTAL)
            {
                minPosition = transform.position.x - moveDistance;
                maxPosition = transform.position.x + moveDistance;
            }
            else
            {
                minPosition = transform.position.z - moveDistance;
                maxPosition = transform.position.z + moveDistance;
            }
        }
    }
Example #10
0
 /// <summary>  Set the moveDirection of this drawer. This method is cleaner than doing it via the public property </summary>
 /// <param name="newAxis"></param>
 public void SetMoveAxis(MovementAxis newAxis)
 {
     this.moveDirection       = newAxis;
     this.actualMoveDirection = newAxis;
     this.moveAxis            = (this.originalRot * this.MoveAxis()).normalized;
 }
Example #11
0
        internal static Vector2 InternalCalculateOffset(ref Bounds viewBounds, ref Bounds contentBounds, MovementAxis moveDirection, MovementType movementType, ref Vector2 delta)
        {
            Vector2 offset = Vector2.zero;

            if (movementType == MovementType.Unrestricted)
            {
                return(offset);
            }

            Vector2 min = contentBounds.min;
            Vector2 max = contentBounds.max;

            // min/max offset extracted to check if approximately 0 and avoid recalculating layout every frame (case 1010178)
            if (moveDirection == MovementAxis.Horizontal)
            {
                min.x += delta.x;
                max.x += delta.x;

                float maxOffset = viewBounds.max.x - max.x;
                float minOffset = viewBounds.min.x - min.x;

                if (minOffset < -0.001f)
                {
                    offset.x = minOffset;
                }
                else if (maxOffset > 0.001f)
                {
                    offset.x = maxOffset;
                }
            }
            else
            {
                min.y += delta.y;
                max.y += delta.y;

                float maxOffset = viewBounds.max.y - max.y;
                float minOffset = viewBounds.min.y - min.y;

                if (maxOffset > 0.001f)
                {
                    offset.y = maxOffset;
                }
                else if (minOffset < -0.001f)
                {
                    offset.y = minOffset;
                }
            }

            return(offset);
        }
Example #12
0
        protected void ApplyMovement(float _inputDirection, MovementAxis movementAxis)
        {
            bool isLockedForAttack  = (controller.slots.physicsObject.IsOnSurface()) ? IsLockedForAttack(Attack.ActionType.GroundMoving) : IsLockedForAttack(Attack.ActionType.AirMoving);
            bool isOverriddenByDash = controller.isDashing;
            bool isRunning          = false;

            if (runSettings.canRun && controller.slots.input && controller.slots.input.isRunButtonDown)
            {
                if ((controller.slots.physicsObject.IsOnSurface() || runSettings.canInitiateInAir) || currentMoveType == MoveType.Running)
                {
                    isRunning            = true;
                    isSlowingDownFromRun = false;

                    if (runSettings.runAnimation && currentMoveType != MoveType.Running && Mathf.Abs(_inputDirection) != 0.0f && controller.slots.physicsObject.IsOnSurface() && controller.StateID() == idString)
                    {
                        PlaySecondaryAnimation(runSettings.runAnimation);
                    }

                    currentMoveType = MoveType.Running;
                }
                else
                {
                    if (currentMoveType == MoveType.Running && Mathf.Abs(controller.slots.physicsObject.properties.velocity.x) > movementProperties.speed)
                    {
                        isSlowingDownFromRun = true;
                        PlayAnimation();
                    }

                    currentMoveType = MoveType.Walking;
                }
            }
            else
            {
                if (currentMoveType == MoveType.Running && Mathf.Abs(controller.slots.physicsObject.properties.velocity.x) > movementProperties.speed)
                {
                    isSlowingDownFromRun = true;
                    PlayAnimation();
                }

                currentMoveType = MoveType.Walking;
            }

            if (Mathf.Abs(controller.slots.physicsObject.properties.velocity.x) <= movementProperties.speed)
            {
                isSlowingDownFromRun = false;
            }

            if (isOverriddenByDash || controller.isKnockbackActive || controller.isStunned || controller.StateID() == WallClingState.idString)
            {
                return;
            }

            bool isLockedIntoJump = (jumpState && !controller.slots.physicsObject.IsOnSurface() && jumpState.IsHorizontalMovementFrozen());

            if (isLockedIntoJump)
            {
                ApplyHorizontalJump(jumpState);
                return;
            }

            if (movementProperties == null)
            {
                return;
            }


            float baseSpeed        = (isRunning) ? runProperties.speed : movementProperties.speed;
            float baseAcceleration = (isRunning) ? runProperties.acceleration : movementProperties.acceleration;
            float baseDeceleration = (isRunning || isSlowingDownFromRun) ? runProperties.deceleration : movementProperties.deceleration;

            //If we're moving diagonally and willMaintainSpeedOnDiagonal is true, cut our speed in each direction in half to compensate
            float diagonalMultiplier = 0.707f;             //Moving in two directions at once is 1.4x faster than just one; therefore, we multiply speed in each direction by 0.707
            bool  isMovingDiagonally = (canMoveVertically && willMaintainSpeedOnDiagonal && Mathf.Abs(controller.axis.x) > 0.0f && Mathf.Abs(controller.axis.y) > 0.0f);
            float speed        = (isMovingDiagonally) ? baseSpeed * diagonalMultiplier : baseSpeed;
            float acceleration = (isMovingDiagonally) ? baseAcceleration * diagonalMultiplier : baseAcceleration;
            float deceleration = baseDeceleration;

            if (controller.currentState.id == CrouchState.idString)
            {
                CrouchState crouchState = controller.GetComponent <CrouchState>();
                if (crouchState)
                {
                    if (crouchState.isSkidComplete && !crouchState.allowAccelerationOnMove)
                    {
                        acceleration = 0.0f;
                        deceleration = 0.0f;
                    }

                    if (crouchState.isSkidComplete)
                    {
                        speed = crouchState.moveSpeed;
                    }
                }
            }

            if (_inputDirection != 0.0f && !controller.isKnockbackActive && !isLockedForAttack && !controller.IsOveriddenByCrouch() && !isSlowingDownFromRun)
            {
                if (movementAxis == MovementAxis.Horizontal)                //Let the controller know that we turned around horizontally
                {
                    Direction.Horizontal actorDirection = controller.direction.horizontal;
                    actorDirection = (_inputDirection > 0.0f) ? Direction.Horizontal.Right : Direction.Horizontal.Left;
                    controller.FaceDirection(actorDirection);
                }

                hasEnded = false;                 //We animate the sprite moving, but only if it's moving horizontally
                if (CanPlayAnimation(movementAxis))
                {
                    Begin();
                }

                if (controller.slots.actor.currentAttack != null && controller.slots.actor.currentAttack.canceledBy.onMove)
                {
                    controller.slots.actor.currentAttack.Cancel();
                }

                if (acceleration != 0.0f)                //Accelerate to the top speed
                {
                    if (movementAxis == MovementAxis.Horizontal)
                    {
                        controller.slots.physicsObject.properties.velocityCap.x  = speed * _inputDirection;
                        controller.slots.physicsObject.properties.acceleration.x = acceleration * _inputDirection;
                        controller.slots.physicsObject.properties.deceleration.x = 0;
                    }
                    else
                    {
                        controller.slots.physicsObject.properties.velocityCap.y  = speed * _inputDirection;
                        controller.slots.physicsObject.properties.acceleration.y = acceleration * _inputDirection;
                        controller.slots.physicsObject.properties.deceleration.y = 0;
                    }
                }
                else                 //Immediately go at top speed
                {
                    if (movementAxis == MovementAxis.Horizontal)
                    {
                        controller.slots.physicsObject.properties.velocityCap.x = speed * _inputDirection;
                        controller.slots.physicsObject.SetVelocityX(speed * _inputDirection);
                        controller.slots.physicsObject.properties.acceleration.x = 0.0f;
                        controller.slots.physicsObject.properties.deceleration.x = 0.0f;
                    }
                    else
                    {
                        controller.slots.physicsObject.properties.velocityCap.y = speed * _inputDirection;
                        controller.slots.physicsObject.SetVelocityY(speed * _inputDirection);
                        controller.slots.physicsObject.properties.acceleration.y = 0.0f;
                        controller.slots.physicsObject.properties.deceleration.y = 0.0f;
                    }
                }
            }
            else                          //We can't move directly, but we can apply residual deceleration
            {
                if (deceleration != 0.0f) //Decelerate gradually to a stop
                {
                    if (movementAxis == MovementAxis.Horizontal)
                    {
                        controller.slots.physicsObject.properties.acceleration.x = 0.0f;
                        controller.slots.physicsObject.properties.deceleration.x = deceleration;

                        if (Mathf.Abs(controller.slots.physicsObject.properties.velocity.x) <= 0.0f && (controller.slots.physicsObject.IsOnSurface() || canMoveVertically))
                        {
                            if (!hasEnded)
                            {
                                if (!controller.isKnockbackActive && controller.StateID() != LadderState.idString)
                                {
                                    controller.SetStateToDefault();
                                }
                            }

                            End();
                        }
                    }
                    else
                    {
                        controller.slots.physicsObject.properties.acceleration.y = 0.0f;
                        controller.slots.physicsObject.properties.deceleration.y = deceleration;
                    }
                }
                else                 //Stop immediately
                {
                    if (movementAxis == MovementAxis.Horizontal)
                    {
                        controller.slots.physicsObject.properties.acceleration.x = 0.0f;
                        controller.slots.physicsObject.properties.deceleration.x = 0.0f;
                        controller.slots.physicsObject.SetVelocityX(0.0f);

                        if (!hasEnded)
                        {
                            if (!controller.isKnockbackActive && controller.StateID() != LadderState.idString && (controller.slots.physicsObject.IsOnSurface() || canMoveVertically) && controller.StateID() != CrouchState.idString)
                            {
                                //Default if:
                                //You are on the ground, AND !canMoveVertically
                                //Or, you are in the air
                                controller.SetStateToDefault();
                            }
                        }

                        //Debug.Log("Ending");

                        End();
                    }
                    else
                    {
                        controller.slots.physicsObject.properties.acceleration.y = 0.0f;
                        controller.slots.physicsObject.properties.deceleration.y = 0.0f;
                        controller.slots.physicsObject.SetVelocityY(0.0f);
                    }
                }
            }
        }
Example #13
0
    // Update is called once per frame
    void FixedUpdate()
    {
        Quaternion newRotation;

        bool  can_move = true;
        float vAxis    = Input.GetAxis("Vertical");
        float hAxis    = Input.GetAxis("Horizontal");

        // de estar conectado el kinect vera el moviento y retornara lo que ha movido
        // de no ser asi pasara los valores como estan
        //comentar cuando se prueba sin kinect
        if (sensor != null)
        {
            if (sensor.IsOpen != null && sensor.IsOpen)
            {
                MovementAxis movement_axis = moveWithKinect(hAxis, vAxis);
                hAxis = (float)movement_axis.xAxis;
                vAxis = (float)movement_axis.yAxis;
            }
        }


        //movement = new Vector3 (hAxis, vAxis, 0)*speed;
        movement = new Vector3(hAxis, vAxis, 0) * speed * Time.deltaTime;
        if (rig.transform.position.x + movement.x > distanceMovementX || rig.transform.position.x + movement.x < -distanceMovementX)
        {
            hAxis    = 0;
            movement = new Vector3(hAxis, vAxis, 0) * speed;
        }
        if (rig.transform.position.y + movement.y > initialY || rig.transform.position.y + movement.y < 24)
        {
            vAxis    = 0;
            movement = new Vector3(hAxis, vAxis, 0) * speed;
        }
        //Debug.Log (movement);
        //if (can_move) {
        //rig.MovePosition (transform.position + movement);
        rig.transform.position = transform.position + movement;
        //}

        //rig.AddForce ( movement);
        //rig.velo


        //esto es para controlar ña rotacion apenas se mueva el avion en cualquiera de las dos direcciones (X,y)
        //if (hAxis == 0)
        if (hAxis == 0 || vAxis == 0)
        {
            transform.Rotate(-vAxis * 0.5f, 0, -hAxis * 4);
        }

        if (useRestitution)
        {
            if (hAxis == 0 && vAxis == 0)
            {
                Vector3 startPos = transform.position;
                Vector3 endPos   = new Vector3(0, initialY, startPos.z);
                transform.position = Vector3.Lerp(startPos, endPos, 0.05f);
            }
        }

        newRotation        = Quaternion.AngleAxis(0, Vector3.up);
        transform.rotation = Quaternion.Slerp(transform.rotation, newRotation, .05f);
    }
Example #14
0
        /// <summary> Project an absolute position onto the plane formed by the Hing Joint's normal. </summary>
        /// <returns></returns>
        public static Vector3 ProjectOnTranform2D(Vector3 absPos, Transform relativeTo, MovementAxis normal)
        {
            Vector3 res = ProjectOnTranform(absPos, relativeTo);

            res[(int)normal] = 0;
            return(res);
        }
 public void setActiveAxes(MovementAxis activeAxes)
 {
     moveTool.setActiveAxes(activeAxes);
 }