Inheritance: MonoBehaviour
コード例 #1
0
    public virtual void down()
    {
        RaycastHit2D hit = Physics2D.Raycast(transform.position, -Vector2.up, rayLength, 1 << LayerHelper.getLayer(LayerHelper.Layer.GOUND_NO_COLLISION));

        if (hit.collider != null)
        {
            OneWayPlatform oneWayPlatForm = hit.collider.gameObject.GetComponent <OneWayPlatform>();
            oneWayPlatForm.unblock(this.name, 0.1f);
        }
    }
コード例 #2
0
 void TryDisablingPlatforms()
 {
     if (m_ControlledCollider.IsGrounded() && m_CanPassThroughOneWayPlatforms && GetDirInput("Move").m_Direction == DirectionInput.Direction.Down)
     {
         OneWayPlatform oneWayPlatform = m_ControlledCollider.GetGroundedInfo().GetGroundTransform().GetComponentInChildren <OneWayPlatform>();
         if (oneWayPlatform)
         {
             oneWayPlatform.DisableForObject(m_CharacterController.GetComponent <Collider>());
         }
     }
 }
コード例 #3
0
    // Update is called once per frame
    void Update()
    {
        otherScript = gameObject.GetComponent<OneWayPlatform>();

        vertAx = Input.GetAxis (jumpAxisName);
        bool drop = false;

        if(Input.GetAxis (jumpAxisName) < 0)
            drop = true;

         if (drop && canDrop) {
            Drop();
        }
        if (isColliding)
                        otherScript.isClose = true;
    }
コード例 #4
0
        static bool preSolve(cpArbiter arb, cpSpace space, object o)
        {
            cpShape a, b;

            arb.GetShapes(out a, out b);

            OneWayPlatform platform = (OneWayPlatform)a.userData;            // (OneWayPlatform*)cpShapeGetUserData(a);

            if (cpVect.cpvdot(arb.GetNormal(), platform.n) < 0)
            {
                arb.Ignore();                // cpArbiterIgnore(arb);
                return(false);
            }

            return(true);
        }
コード例 #5
0
ファイル: Player.cs プロジェクト: parkovski/scifi
        protected void BaseCollisionEnter2D(Collision2D collision)
        {
            if (collision.gameObject.tag == "Ground")
            {
                ++pGroundCollisions;
                pNumJumps         = 0;
                pIsTouchingGround = true;
                groundField.Update(this);

                var oneWay = collision.gameObject.GetComponent <OneWayPlatform>();
                if (oneWay != null)
                {
                    sCurrentOneWayPlatform = oneWay;
                }
            }
        }
コード例 #6
0
    protected void CheckOneWayPlatformFallThrough()
    {
        if (_characterPhysicsManager.lastMoveCalculationResult.collisionState.below &&
            (_gameManager.inputStateManager.GetButtonState("Fall").buttonPressState & ButtonPressState.IsPressed) != 0 &&
            _playerController.currentPlatform != null &&
            _playerController.currentPlatform.layer == LayerMask.NameToLayer("OneWayPlatform"))
        {
            OneWayPlatform oneWayPlatform = _playerController.currentPlatform.GetComponent <OneWayPlatform>();

            Logger.Assert(oneWayPlatform != null, "OneWayPlatform " + _playerController.currentPlatform.name + " has no 'OneWayPlatform' script attached. This script is needed in order to allow the player to fall through.");

            if (oneWayPlatform != null)
            {
                oneWayPlatform.TriggerFall();
            }
        }
    }
コード例 #7
0
ファイル: Player.cs プロジェクト: parkovski/scifi
        protected void BaseCollisionExit2D(Collision2D collision)
        {
            if (collision.gameObject.tag == "Ground")
            {
                if (--pGroundCollisions == 0)
                {
                    pIsTouchingGround = false;
                    groundField.Update(this);
                }

                var oneWay = collision.gameObject.GetComponent <OneWayPlatform>();
                if (oneWay != null)
                {
                    sCurrentOneWayPlatform = null;
                }
            }
        }
コード例 #8
0
        private void verticalCollision(ref Vector3 velocity)
        {
            float directionY = Mathf.Sign(velocity.y);
            float rayLength  = Mathf.Abs(velocity.y) + Raycaster.c_SkinWidth;

            for (int i = 0; i < m_Raycaster.VerticalRayCount; i++)
            {
                Vector2 rayOrigin = (directionY == -1) ? m_Raycaster.Origins.BottomLeft : m_Raycaster.Origins.TopLeft;

                // offset horizontal direction to precise detection
                rayOrigin += Vector2.right * (m_Raycaster.VerticalRaySpacing * i + velocity.x);
                RaycastHit2D hit = Physics2D.Raycast(rayOrigin, Vector2.up * directionY, rayLength, m_Raycaster.CollisionLayer);

                Debug.DrawRay(rayOrigin, Vector2.up * directionY * rayLength, Color.yellow);

                if (hit)
                {
                    OneWayPlatform oneWayPlatform = null;
                    if (hit.collider.TryGetComponent(out oneWayPlatform))
                    {
                        if (directionY == 1 || hit.distance == 0)
                        {
                            continue;
                        }

                        if (m_IsFallingThrough)
                        {
                            continue;
                        }

                        if (directionY == -1 && Mathf.Sign(GetComponent <BasicMovementController2D>().m_InputBuffer.Input.y) == -1 && hit.collider.transform.parent != null && hit.collider.transform.parent.GetComponent <Ladder>())
                        {
                            continue;
                        }
                    }

                    // change velocity y so it stops at the hit point
                    velocity.y = (hit.distance - Raycaster.c_SkinWidth) * directionY;
                    rayLength  = hit.distance;

                    if (m_CollisionInfo.ClimbingSlope)
                    {
                        velocity.x =
                            velocity.y / Mathf.Tan(m_CollisionInfo.Curr_SlopeAngle * Mathf.Deg2Rad);
                    }

                    setBelow(directionY == -1, hit.normal);
                    setAbove(directionY == 1, hit.normal);
                }
            }

            // to check if there is a new slope
            if (m_CollisionInfo.ClimbingSlope)
            {
                float directionX = Mathf.Sign(velocity.x);
                rayLength = Math.Abs(velocity.x) + Raycaster.c_SkinWidth;
                Vector2 rayOrigin = ((directionX == -1) ? m_Raycaster.Origins.BottomLeft : m_Raycaster.Origins.BottomRight) +
                                    Vector2.up * velocity.y;

                RaycastHit2D hit = Physics2D.Raycast(rayOrigin, Vector2.right * directionX, rayLength, m_Raycaster.CollisionLayer);

                if (hit)
                {
                    float slopeAngle = Vector2.Angle(hit.normal, Vector2.up);
                    if (slopeAngle != m_CollisionInfo.Curr_SlopeAngle)
                    {
                        //Debug.Log("New slope");
                        velocity.x = (hit.distance - Raycaster.c_SkinWidth) * directionX;
                        m_CollisionInfo.Curr_SlopeAngle = slopeAngle;
                    }
                }
            }
        }
コード例 #9
0
        private void horizontalCollision(ref Vector3 velocity)
        {
            float directionX = m_MovingDirection;
            float rayLength  = Mathf.Abs(velocity.x) + Raycaster.c_SkinWidth;

            if (Mathf.Abs(velocity.x) < Raycaster.c_SkinWidth)
            {
                rayLength = 2 * Raycaster.c_SkinWidth;
            }

            for (int i = 0; i < m_Raycaster.HorizontalRayCount; i++)
            {
                Vector2 rayOrigin = (directionX == -1) ? m_Raycaster.Origins.BottomLeft : m_Raycaster.Origins.BottomRight;

                rayOrigin += Vector2.up * (m_Raycaster.HorizontalRaySpacing * i);
                RaycastHit2D hit = Physics2D.Raycast(rayOrigin, Vector2.right * directionX, rayLength, m_Raycaster.CollisionLayer);

                Debug.DrawRay(rayOrigin, Vector2.right * directionX * rayLength, Color.yellow);

                if (hit)
                {
                    if (hit.distance == 0)
                    {
                        continue;
                    }

                    float slopeAngle = Vector2.Angle(hit.normal, Vector2.up);

                    // climbing a slope
                    if (i == 0 && slopeAngle <= m_MaxClimbAngle)
                    {
                        // if descending, reset velocity. Since descendSlope has changed velocity.x
                        if (m_CollisionInfo.DescendingSlope)
                        {
                            m_CollisionInfo.DescendingSlope = false;
                            velocity = Raw_Velocity;
                        }

                        float distanceToSlopeStart = 0;
                        // its a new slope
                        if (slopeAngle != m_CollisionInfo.Prev_SlopeAngle)
                        {
                            distanceToSlopeStart = hit.distance - Raycaster.c_SkinWidth;
                            velocity.x          -= distanceToSlopeStart * directionX;
                        }
                        climbSlope(ref velocity, slopeAngle, hit.normal);

                        velocity.x += distanceToSlopeStart * directionX;
                    }

                    // only check other raycasts if not climbing
                    if (!m_CollisionInfo.ClimbingSlope || slopeAngle > m_MaxClimbAngle)
                    {
                        OneWayPlatform oneWayPlatform = null;
                        if (hit.collider.TryGetComponent(out oneWayPlatform))
                        {
                            continue;
                        }

                        // change velocity x so it stops at the hit point
                        velocity.x = (hit.distance - Raycaster.c_SkinWidth) * directionX;
                        rayLength  = hit.distance;

                        if (m_CollisionInfo.ClimbingSlope)
                        {
                            velocity.y =
                                Mathf.Tan(m_CollisionInfo.Curr_SlopeAngle * Mathf.Deg2Rad) *
                                Mathf.Abs(velocity.x);
                        }

                        setLeft(directionX == -1, hit.normal);
                        setRight(directionX == 1, hit.normal);
                    }
                }
            }
        }
コード例 #10
0
ファイル: APlayer.cs プロジェクト: moniika/Booya
 /// <summary>
 /// Raises the controller collider hit event.
 /// </summary>
 /// <param name="hit">Hit.</param>
 void OnControllerColliderHit(ControllerColliderHit hit)
 {
     if (hit.collider.tag == "Platform") {
         lastPlatform = hit.gameObject.GetComponentInChildren<OneWayPlatform> ();
     } else if (hit.collider.tag == "Human") {
         hit.gameObject.GetComponentInChildren<HumanNPC> ().Eaten();
         //TODO perform feeding animation
         PowerLevel += 1.0f;
     }
 }
コード例 #11
0
ファイル: APlayer.cs プロジェクト: moniika/Booya
    /// <summary>
    /// Control input logic.
    /// </summary>
    protected void InputLogic()
    {
        if (!IsGrounded ()) {
            lastPlatform = null;
        }

        if (!IsHorizontalLocked && Input.GetButton ("left-" + ControllerType + ControllerNumber)) {
            // move left
            if (lastAnimation != AnimationType.LEFT) {
                //TODO perform left animation
                lastAnimation = AnimationType.LEFT;
            }
            if (GameContants.DebugMode)
                Debug.Log (PlayerID + "left");
            moveHorizontal (-1);
        } else if (!IsHorizontalLocked && Input.GetButton ("right-" + ControllerType + ControllerNumber)) {
            // move right
            if (lastAnimation != AnimationType.RIGHT) {
                //TODO perform right animation
                lastAnimation = AnimationType.RIGHT;
            }
            if (GameContants.DebugMode)
                Debug.Log (PlayerID + "right");
            moveHorizontal (1);
        } else if (!IsActionDisabled && Input.GetButton ("specialup-" + ControllerType + ControllerNumber)) {
            // special up
            if (lastAnimation != AnimationType.SPECIALUP) {
                //TODO perform special up animation
                lastAnimation = AnimationType.SPECIALUP;
            }
            if (GameContants.DebugMode)
                Debug.Log (PlayerID + "specialup");
            DoSpecialUp ();
        } else if (!IsGrounded () && !IsActionDisabled && Input.GetButton ("specialdown-" + ControllerType + ControllerNumber)) {
            // special down
            if (lastAnimation != AnimationType.SPECIALDOWN) {
                //TODO perform special down animation
                lastAnimation = AnimationType.SPECIALDOWN;
            }
            if (GameContants.DebugMode)
                Debug.Log (PlayerID + "specialdown");
            DoSpecialDown();
        } else {
            if(lastAnimation != AnimationType.IDLE) {
                //TODO perform idle animation
                lastAnimation = AnimationType.IDLE;
            }
        }
    }
コード例 #12
0
 private void SetOneWayPlatformsContainsStandingOn(GameObject standingOn)
 {
     SetOneWayPlatformsContainsStandingOn(OneWayPlatform.Contains(standingOn.layer));
 }
コード例 #13
0
        public override void OnEnter()
        {
            base.OnEnter();

            platformInstance = new OneWayPlatform();

            SetSubTitle("One way platforms are trivial in Chipmunk using a very simple collision callback.");

            space.SetIterations(10);
            space.SetGravity(new cpVect(0, -100));

            cpBody  body, staticBody = space.GetStaticBody();
            cpShape shape;

            // Create segments around the edge of the screen.
            shape = space.AddShape(new cpSegmentShape(staticBody, new cpVect(-320, -240), new cpVect(-320, 240), 0.0f));
            shape.SetElasticity(1.0f);
            shape.SetFriction(1.0f);
            shape.SetFilter(NOT_GRABBABLE_FILTER);

            shape = space.AddShape(new cpSegmentShape(staticBody, new cpVect(320, -240), new cpVect(320, 240), 0.0f));
            shape.SetElasticity(1.0f);
            shape.SetFriction(1.0f);
            shape.SetFilter(NOT_GRABBABLE_FILTER);

            shape = space.AddShape(new cpSegmentShape(staticBody, new cpVect(-320, -240), new cpVect(320, -240), 0.0f));
            shape.SetElasticity(1.0f);
            shape.SetFriction(1.0f);
            shape.SetFilter(NOT_GRABBABLE_FILTER);

            // Add our one way segment
            shape = space.AddShape(new cpSegmentShape(staticBody, new cpVect(-160, -100), new cpVect(160, -100), 10.0f));
            shape.SetElasticity(1.0f);
            shape.SetFriction(1.0f);

            shape.SetCollisionType(COLLISION_TYPE_ONE_WAY);
            shape.SetFilter(NOT_GRABBABLE_FILTER);

            // We'll use the data pointer for the OneWayPlatform struct
            platformInstance.n = new cpVect(0, 1);             // let objects pass upwards
            shape.userData     = platformInstance;


            // Add a ball to test it out
            float radius = 15.0f;

            body = space.AddBody(new cpBody(10.0f, cp.MomentForCircle(10.0f, 0.0f, radius, cpVect.Zero)));
            body.SetPosition(new cpVect(0, -200));
            body.SetVelocity(new cpVect(0, 170));

            shape = space.AddShape(new cpCircleShape(body, radius, cpVect.Zero));
            shape.SetElasticity(0.0f);
            shape.SetFriction(0.9f);
            shape.SetCollisionType(2);

            cpCollisionHandler handler = space.AddWildcardHandler(COLLISION_TYPE_ONE_WAY);

            handler.preSolveFunc = preSolve;


            Schedule();
        }