//The character has been moved, either via script or via editor. Adjust position to make up for this void CheckForUpdatedPosition() { if (transform.position != m_CapsuleTransform.GetPosition()) { m_CapsuleTransform.SetPosition(transform.position); } }
public bool CanApplyEntireMovement(CapsuleTransform a_Transform) { if (a_Transform.GetPosition() != m_Position) { if (!a_Transform.CanMove(m_Position - a_Transform.GetPosition(), true)) { return(false); } } if (a_Transform.GetUpDirection() != m_UpDirection) { if (!a_Transform.CanRotate(m_UpDirection, m_RotateMethod)) { return(false); } } if (a_Transform.GetLength() != m_Length) { if (!a_Transform.CanBeResized(m_Length, m_ResizeMethod)) { return(false); } } return(true); }
//Query whether this module can be active, given the current state of the character controller (velocity, isGrounded etc.) //Called every frame when inactive (to see if it could be) and when active (to see if it should not be) public override bool IsApplicable() { if (m_ControlledCollider.IsGrounded() || (DoesInputExist("Crouch") && GetButtonInput("Crouch").m_IsPressed) || GetDirInput("Move").m_Direction == DirectionInput.Direction.Down || m_CharacterController.DidJustJump()) { return(false); } //Prevent overriding walljumps if (GetDirInput("Move").IsInThisDirection(m_ControlledCollider.GetEdgeCastInfo().GetWallNormal())) { return(false); } if ((m_CharacterController.GetJumpIsCached()) && m_ControlledCollider.IsTouchingEdge()) { //Move up to avoid transitioning into a wallrun. //Also used to prevent small distance jumps. CEdgeCastInfo edgeInfo = m_ControlledCollider.GetEdgeCastInfo(); CapsuleTransform copy = m_ControlledCollider.GetCapsuleTransformCopy(); Vector3 headStartDisplacement = edgeInfo.GetEdgeNormal() * (m_ControlledCollider.GetRadius() + 0.1f) + edgeInfo.GetWallNormal() * 0.015f; if (!copy.CanMove(headStartDisplacement, true)) { return(false); } copy.Move(headStartDisplacement); m_ProposedNewPosition = copy.GetPosition(); return(true); } return(false); }
public void ApplyEntireMovement(CapsuleTransform a_Transform) { if (a_Transform.GetPosition() != m_Position) { a_Transform.SetPosition(m_Position); } if (a_Transform.GetUpDirection() != m_UpDirection) { a_Transform.Rotate(m_UpDirection, m_RotateMethod); } if (a_Transform.GetLength() != m_Length) { a_Transform.SetLength(m_Length, m_ResizeMethod); } }
protected override void GeneratePath() { CEdgeCastInfo info = m_ControlledCollider.GetEdgeCastInfo(); m_Path.Clear(); CapsuleTransform copy = m_ControlledCollider.GetCapsuleTransformCopy(); //First node is in edgehang alignment, moving away from the edge mildly CapsuleMovementPathNode newNode = m_Path.CreateFirstNode(copy); Vector3 upCenter = info.GetProposedHeadPoint(); upCenter += m_ControlledCollider.GetEdgeCastInfo().GetWallNormal() * 0.03f; copy.SetUpCenter(upCenter); copy.Rotate(info.GetUpDirection(), RotateMethod.FromTop); newNode = m_Path.DuplicateAndAddLastNode(); newNode.CopyFromTransform(copy); //Second node moves up along local up, until the bottom can slide over the edge newNode = m_Path.DuplicateAndAddLastNode(); newNode.m_Duration = m_MoveUpTime; float contactDot = Vector3.Dot(info.GetEdgeNormal(), info.GetEdgePoint()); float bottomDot = Vector3.Dot(info.GetEdgeNormal(), copy.GetDownCenter()) - m_ControlledCollider.GetRadius() - m_MoveUpMargin; float normalDot = Vector3.Dot(info.GetEdgeNormal(), copy.GetUpDirection()); float rawDistance = contactDot - bottomDot; float distance = rawDistance / normalDot; newNode.m_Position += copy.GetUpDirection() * distance; newNode.ApplyEntireMovement(copy); //Third node snaps the capsule to the "upright" position for the ground it's going to stand on newNode = m_Path.DuplicateAndAddLastNode(); newNode.m_Duration = 0.0f; newNode.m_UpDirection = (m_CharacterController.GetAlignsToGround()) ? info.GetEdgeNormal() : Vector3.up; newNode.m_RotateMethod = RotateMethod.FromBottom; newNode.ApplyEntireMovement(copy); newNode.m_Position = copy.GetPosition(); //Final node moves the capsule over the ground newNode = m_Path.DuplicateAndAddLastNode(); newNode.m_Duration = m_MoveSideTime; Vector3 direction = CState.GetDirectionAlongNormal(-info.GetWallNormal(), info.GetEdgeNormal()); newNode.m_Position += direction * m_MoveSideDistance; newNode.ApplyEntireMovement(copy); }
public void CopyFromTransform(CapsuleTransform a_Transform) { m_Position = a_Transform.GetPosition(); m_UpDirection = a_Transform.GetUpDirection(); m_Length = a_Transform.GetLength(); }