void BeginClimbing(ClimbingSurface c, Vector3 startAt, int triIndex) { Debug.Log("Begin Climb"); body.useGravity = false; toClimb = c; climbing = true; transform.position = startAt + (contactNormal * collisionSphere.bounds.extents.y); SetGravitySurface(c.GetComponent <CustomGravitySurface>()); }
protected virtual void FixedUpdate() { var hit = Physics2D.Raycast(this.transform.position - Vector3.forward * 2, Vector3.forward, 6.0f, this.WhatIsSurfaceForClimbing); if (hit.collider) { this.climbingSurface = hit.collider.GetComponent <ClimbingSurface>(); } else { this.climbingSurface = null; } this.IsGrounded.Value = Physics2D.OverlapCircle(this.GroundCheck.position, this.GroundRadius, this.WhatIsGround | this.WhatIsLevelObject | this.WhatIsEnemy | this.WhatIsCharacter) && !this.IsClimbed.Value; this.CanClimb.Value = Physics2D.OverlapCircle(this.ClimbCheck.position, this.ClimbRadius, this.WhatIsSurfaceForClimbing) && this.climbingSurface; if (this.IsClimbed.Value && this.climbingSurface) { var horizontalValue = this.HorizontalValue.Value * this.CreepSpeed; var verticalValue = this.VerticalValue.Value * this.CreepSpeed; if (this.climbingSurfaceOnRightIsMissing && horizontalValue > 0) { horizontalValue = 0; } if (this.climbingSurfaceOnLeftIsMissing && horizontalValue < 0) { horizontalValue = 0; } if (this.climbingSurfaceOnTopIsMissing && verticalValue > 0) { verticalValue = 0; } if (this.climbingSurfaceOnBottomIsMissing && verticalValue < 0) { verticalValue = 0; } if (verticalValue < 0 && this.isTopOnStairs && this.isBottomNotOnStairs) { this.IsGrounded.Value = true; this.IsClimbed.Value = false; this.rigidBody.gravityScale = 1.0f; } else { this.rigidBody.velocity = new Vector2(horizontalValue, verticalValue); } } if (!this.IsClimbed.Value) { this.rigidBody.velocity = new Vector2(this.HorizontalValue.Value * this.RunSpeed, this.rigidBody.velocity.y); } this.anim.SetFloat("Speed", Mathf.Abs(this.HorizontalValue.Value)); if (this.IsClimbed.Value && this.climbingSurface) { this.anim.SetFloat("ClimbSpeed", Mathf.Max(Mathf.Abs(this.HorizontalValue.Value), Mathf.Abs(this.VerticalValue.Value))); } this.anim.SetFloat("JumpSpeed", this.rigidBody.velocity.y); }