void LateUpdate() { Vector3 delta = transform.position - prevPosition; prevPosition = transform.position; foreach (Transform t in stuckObjects) { PawnAABB3D pawn = t.GetComponent <PawnAABB3D>(); if (pawn) { PawnAABB3D.CollisionResults results = pawn.Move(delta); // TODO: move into PAWNAABB3D class? // convert local distance into world space Vector3 worldSpaceDistance = t.TransformVector(results.distanceLocal); // add to player position t.transform.position += worldSpaceDistance; } else { t.transform.Translate(delta); } } }
/// <summary> /// Perform collision detection by calling the PawnAABB's collision detection methods. /// The results of collision detection are then applied. /// </summary> protected void DoCollisions() { // clamp velocity to maxSpeed if (isGrounded && Mathf.Abs(player.velocity.x) > player.maxSpeed) { // FIXME: this might not be working correctly on slopes... player.velocity.x = Mathf.Sign(player.velocity.x) * player.maxSpeed; } PawnAABB3D.CollisionResults results = player.pawn.Move(player.velocity * Time.deltaTime); if (results.hitTop || results.hitBottom) { player.velocity.y = 0; } if (results.hitLeft || results.hitRight) { player.velocity.x = 0; } isGrounded = results.hitBottom || results.ascendSlope; // convert local distance into world space Vector3 worldSpaceDistance = player.transform.TransformVector(results.distanceLocal); // add to player position player.transform.position += worldSpaceDistance; }
/// <summary> /// Perform collision detection by calling the PawnAABB's collision detection methods. /// The results of collision detection are then applied. /// </summary> private void DoCollisions() { PawnAABB3D.CollisionResults results = pawn.Move(velocity * Time.deltaTime); if (results.hitTop || results.hitBottom) { velocity.y = 0; } if (results.hitLeft || results.hitRight) { velocity.x = 0; } isGrounded = results.hitBottom || results.ascendSlope; float distanceFromPlayer = Vector2.Distance(Player.PlayerController.main.transform.position, transform.position); if (isGrounded) { if (distanceFromPlayer < MAX_DISTANCE) { isBurrowing = true; preBurrowPoint = transform.position; } } else if (distanceFromPlayer < 1) { SetHugging(); } if (!isHugging) { transform.position += results.distanceLocal; } }