コード例 #1
0
ファイル: Controller.cs プロジェクト: LemonadeSerg/2DTesting
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (collision.gameObject.CompareTag("Climb"))
     {
         climbable = collision.GetComponent <Climbable>();
         canClimb  = true;
     }
 }
コード例 #2
0
ファイル: ActClimbing.cs プロジェクト: nmbswls/Platform2DTest
    public override void Initialization(ActCharacterNew character)
    {
        base.Initialization(character);

        CurrentLadderClimbingSpeed = Vector2.zero;
        LadderColliding            = false;
        CurrentLadder = null;
    }
コード例 #3
0
 /// <summary>
 /// Handles checking if the player is no longer over a climbable object. Sets gravity back
 /// </summary>
 /// <param name="otherCollider">The collider hitting this collider</param>
 void OnTriggerExit2D(Collider2D otherCollider)
 {
     if (PlayerManager.Instance.isAnchored() && otherCollider.gameObject.GetComponent <Climbable>() != null)
     {
         _rigidbody.gravityScale = _originalGravityScale;
         _climbable  = null;
         _isClimbing = false;
     }
 }
コード例 #4
0
        /// <summary>
        /// Setup on start of play
        /// </summary>
        private void Awake()
        {
            _rb  = GetComponent <Rigidbody2D>();
            _col = GetComponent <BoxCollider2D>();

            _currentSurface = new Climbable();

            _layerMask = gameObject.layer;
        }
コード例 #5
0
ファイル: Player.cs プロジェクト: chryses46/Patched
 private void OnTriggerStay(Collider other)
 {
     if (hasArms)
     {
         Climbable climbable = other.GetComponent <Climbable>();
         if (climbable != null && rb.velocity.y < 0f)
         {
             climbing = climbable;
         }
     }
 }
コード例 #6
0
 public override void OnWallHit(Vector3 normal, Vector3 point, GameObject go, PhysicsProp prop)
 {
     if (!IsOwner)
     {
         return;
     }
     PreviousWallNormal = normal;
     PreviousWallPos    = point;
     PreviousWall       = prop as Climbable;
     utils.ResetTimer(CLIMB_TIMER);
 }
コード例 #7
0
ファイル: Player.cs プロジェクト: chryses46/Patched
 private void OnTriggerEnter(Collider other)
 {
     if (hasArms)
     {
         Climbable climbable = other.GetComponent <Climbable>();
         if (climbable != null)
         {
             climbing = climbable;
         }
     }
 }
コード例 #8
0
 public override void FixedUpdate()
 {
     if (!IsOwner)
     {
         return;
     }
     if (utils.CheckTimer(CLIMB_TIMER))
     {
         PreviousWall = null;
     }
     HandleClimbableSurfaces();
 }
コード例 #9
0
        /// <summary>
        ///
        /// </summary>
        public void RemoveClimbable()
        {
            if (Climbables > 0)
            {
                Climbables--;
            }

            if (Climbables == 0 && State.IsClimbing())
            {
                StopClimbing();

                Climbable = null;
            }
        }
コード例 #10
0
    public void ReleaseClimbable(bool gently = false)
    {
        if (IsClimbing())
        {
            if (Active)
            {
                PhysicsActive = true;
            }

            dontGrabClimbableDelay = 0.25f;
            if (gently)
            {
                dontGrabSameClimbableDelay = 0.65f;
            }
            targetClimbable  = null;
            climbUpRequest   = false;
            climbDownRequest = false;
        }
    }
コード例 #11
0
    /// <summary>
    /// Handles checking if the player is over a climbable object. Changes the gravity to allow climbing
    /// </summary>
    /// <param name="otherCollider">The collider hitting this collider</param>
    void OnTriggerEnter2D(Collider2D otherCollider)
    {
        // Store off a reference to the current platform you are one
        if (isGrounded() && otherCollider.tag == "Ground")
        {
            _currentPlatform = otherCollider.gameObject;
        }

        // Ladder logic to allow climbing
        if (PlayerManager.Instance.isAnchored() && otherCollider.gameObject.GetComponent <Climbable>() != null)
        {
            _rigidbody.gravityScale = 0;
            _climbable = otherCollider.gameObject.GetComponent <Climbable>();
        }

        // Process if you hit a powerup, try to use it
        if (PlayerManager.Instance.isAnchored() && otherCollider.gameObject.tag == "Powerup")
        {
            otherCollider.gameObject.GetComponent <Powerup>().use();
        }
    }
コード例 #12
0
ファイル: Player.cs プロジェクト: chryses46/Patched
 public void Jump()
 {
     if (groundingPID.grounded || climbing != null || (hasDoubleJump && doubleJump))
     {
         if (groundingPID.grounded)
         {
             Land();
         }
         if (!(groundingPID.grounded || climbing != null))
         {
             doubleJump = false;
             startGlide();
         }
         if (climbing != null)
         {
             rb.velocity = new Vector2(input.x * speed, 0f);
         }
         groundingPID.Unground();
         rb.velocity = rb.velocity.With(y: jumpVelocity);
         climbing    = null;
     }
 }
コード例 #13
0
 public bool GrabClimbable()
 {
     if (Active)
     {
         if (potentialClimbable != null && !IsTouchingGround() && !IsHoldingSomething && !IsBeingHeldByCharacter() && dontGrabClimbableDelay <= speedThreshold)
         {
             if (potentialClimbable == lastClimbable && dontGrabSameClimbableDelay > speedThreshold)
             {
                 return(false);
             }
             else
             {
                 ReleaseEdge();
                 ReleaseCharacter();
                 PhysicsActive   = false;
                 targetClimbable = potentialClimbable;
                 lastClimbable   = potentialClimbable;
                 if (rigidbody.position.x > targetClimbable.gameObject.transform.position.x)
                 {
                     Turn(Verse.Left);
                 }
                 else
                 {
                     Turn(Verse.Right);
                 }
                 StickToClimbable(targetClimbable.gameObject);
                 rigidbody.velocity = Vector2.zero;
                 return(true);
             }
         }
         else
         {
             return(false);
         }
     }
     return(false);
 }
コード例 #14
0
ファイル: Climber.cs プロジェクト: StellaBialek/GGJ2020
 public void AddClimbable(Climbable c)
 {
     climbables.Add(c);
 }
コード例 #15
0
    private void CalculateProximity()
    {
        RaycastHit2D hit;

        var wasGrounded = grounded;

        hit = Physics2D.BoxCast((Vector2)collider.bounds.center, collider.bounds.size, 0, Vector2.down, 0.1f, groundLayer);
        if (hit.collider != null)
        {
            grounded = true;
        }
        else
        {
            grounded = false;
        }

        if (grounded && !wasGrounded)
        {
            if (effectJumpend != null)
            {
                CmdSpawnEffectJumpend(transform.position + Vector3.down, verse);
            }
        }

        hit = Physics2D.BoxCast((Vector2)collider.bounds.center, collider.bounds.size, 0, Vector2.up, 0.1f, groundLayer);
        if (hit.collider != null)
        {
            nearCeiling = true;
        }
        else
        {
            nearCeiling = false;
        }

        hit = Physics2D.BoxCast((Vector2)collider.bounds.center, collider.bounds.size - new Vector3(0, 0.1f, 0), 0, new Vector2(1, 2), 0.05f, groundLayer);
        if (hit.collider != null)
        {
            nearWallRight = true;
        }
        else
        {
            nearWallRight = false;
        }

        hit = Physics2D.BoxCast((Vector2)collider.bounds.center, collider.bounds.size - new Vector3(0, 0.1f, 0), 0, new Vector2(-1, 2), 0.05f, groundLayer);
        if (hit.collider != null)
        {
            nearWallLeft = true;
        }
        else
        {
            nearWallLeft = false;
        }

        hit = Physics2D.BoxCast((Vector2)collider.bounds.center, collider.bounds.size - new Vector3(0, 0.1f, 0), 0, new Vector2(1, 0), 0.05f, groundLayer);
        if (hit.collider != null)
        {
            nearWallRightHor = true;
        }
        else
        {
            nearWallRightHor = false;
        }

        hit = Physics2D.BoxCast((Vector2)collider.bounds.center, collider.bounds.size - new Vector3(0, 0.1f, 0), 0, new Vector2(-1, 0), 0.05f, groundLayer);
        if (hit.collider != null)
        {
            nearWallLeftHor = true;
        }
        else
        {
            nearWallLeftHor = false;
        }

        hit = Physics2D.BoxCast((Vector2)collider.bounds.center, collider.bounds.size - new Vector3(0, 0.1f, 0), 0, Vector2.one, 0.0f, climbableLayer);
        if (hit.collider != null)
        {
            potentialClimbable = hit.collider.gameObject.GetComponent <Climbable>();
        }
        else
        {
            potentialClimbable = null;
        }

        potentialCharacter = null;
        RaycastHit2D[] hits = Physics2D.CircleCastAll(characterGrabCollider.bounds.center, characterGrabCollider.radius, Vector2.right, 0.0f);
        for (int i = 0; i < hits.Length; i++)
        {
            AnotherCharacterController other = hits[i].collider.gameObject.GetComponent <AnotherCharacterController>();
            if (other != null && other != this)
            {
                potentialCharacter = other;
            }
        }
    }
コード例 #16
0
        ////////////////////
        ///// CLIMBING /////
        ////////////////////

        // TODO: Move to the Player, or to a "Climber" trait.

        /// <summary>
        ///
        /// </summary>
        /// <param name="climbable"></param>
        public void AddClimbable(Climbable climbable)
        {
            Climbables++;

            Climbable = climbable;
        }
コード例 #17
0
    /**
     *
     */
    public void RemoveClimbable()
    {
		if (climbables > 0)
        {
			climbables--;
		}

		if (climbables == 0 && State.IsClimbing())
        {
			StopClimbing();
			climbable = null;
		}
	}
コード例 #18
0
    ////////////////////
    ///// CLIMBING /////
    ////////////////////

    /**
     * @todo Move to the Player, or to a "Climber" trait.
     */

    /**
     *
     */
    public void AddClimbable(Climbable climbable)
    {
		climbables++;

		this.climbable = climbable;
	}
コード例 #19
0
 /// <summary>
 /// Initializes the custom editor.
 /// </summary>
 private void OnEnable()
 {
     _climbableTarget = target as Climbable;
 }
コード例 #20
0
ファイル: Climber.cs プロジェクト: StellaBialek/GGJ2020
 public void RemoveClimbable(Climbable c)
 {
     climbables.Remove(c);
 }
コード例 #21
0
ファイル: Player.cs プロジェクト: chryses46/Patched
 protected virtual void FixedUpdate()
 {
     input = new Vector2(input.x, Mathf.MoveTowards(input.y, 0f, Time.deltaTime * 10f));
     if (groundingPID.groundedTruth || climbing != null)
     {
         ApplyFriction(input == Vector2.zero ? 3f : 1f);
         doubleJump = true;
         if (gliding)
         {
             StopGlide();
         }
     }
     ApplyAccelleration(groundingPID.groundedTruth ? 1f : 0.3f);
     rb.velocity = rb.velocity.With(y: Mathf.Max(rb.velocity.y, gliding ? -2f : -jumpVelocity * 2f));
     if (climbing != null)
     {
         rb.velocity        = Vector3.up * input.y * speed * 0.6f;
         transform.position = climbing.transform.position.With(y: transform.position.y);
         if (transform.position.y > climbing.transform.position.y)
         {
             groundingPID.Unground();
             rb.velocity = rb.velocity.With(y: jumpVelocity);
             climbing    = null;
         }
         else if (transform.position.y < climbing.bottom.position.y)
         {
             climbing = null;
         }
     }
     if (transform.position.y < -20f)
     {
         TakeDamage();
     }
     if (groundingPID.groundedTruth && input.x != 0f)
     {
         if (dustFX.time >= dustFX.main.duration || !dustFX.isPlaying)
         {
             dustFX.Play();
         }
     }
     if (groundingPID.groundedTruth)
     {
         if (Mathf.Abs(input.x) > 0f)
         {
             SetAnim(animRun);
         }
         else
         {
             SetAnim(animIdle);
         }
     }
     else if (climbing)
     {
         SetAnim(animClimb);
     }
     else
     {
         if (gliding)
         {
             SetAnim(animGlide);
         }
         else
         {
             SetAnim(animJump);
         }
     }
 }