Swimming Ability

MAK

New member
Hi

I am creating swimming ability, but i getting some problem.
My requirement is as follow

1. Slope near to sea
2. When character is 75% in water then he stars swimming
3. When character swimming and reach near to sea shore and detects ground then he is back to walking and out of sea

Check Screenshot_1.jpg for my setup

So in ability i set following things
Allow Position Input = true
Allow Rotation Input = true
Use Gravity = false
Use Root Motion Position & Rotation = false
Detect Horizontal Collision = true
Detect Vertical Collision = true

So when activity start i am disabling Gravity from general settings but it still snapping character to ground. Check Screenshot_2,jpg.

So i debug inside code, gravity is not applying that is okey. after further debug i got something that is snapping character to ground which is DeflectVerticalCollisions() function inside CharacterLocomotion.cs

C#:
var localPlatformVerticalDirection = m_Platform != null ? m_Transform.InverseTransformDirection(m_PlatformMovement).y : 0;
                if ((m_Grounded || grounded) && (localMoveDirection.y - localPlatformVerticalDirection) < c_ColliderSpacing && verticalOffset > -c_ColliderSpacing -
                                                                                    ((m_Grounded && m_StickToGround) ? m_Stickiness : 0) - ((m_Grounded && m_AlignToGround) ? m_AlignToGroundDistance : 0)) {
                    localMoveDirection.y += verticalOffset;
                    // Don't allow the character to go through the ground.
                    if (localMoveDirection.y < -m_GroundRaycastHit.distance + localPlatformVerticalDirection) {
                        localMoveDirection.y = -m_GroundRaycastHit.distance + localPlatformVerticalDirection + c_ColliderSpacing;
                    }
                    accumulateGravity = false;
                    // If the character wasn't previously grounded they are now. This allows the character to stick to the ground without the grounded state updating.
                    grounded = true;

                    // Any external force in the vertical direction should be zeroed out so the character can land properly.
                    var dynamicFrictionValue = Mathf.Clamp01(1 - MathUtility.FrictionValue(m_GroundRaycastOriginCollider.material, m_GroundRaycastHit.collider.material, true));
                    var localExternalForce = LocalExternalForce * dynamicFrictionValue;
                    localExternalForce.y = 0;
                    m_ExternalForce = m_Transform.TransformDirection(localExternalForce);
                }

and i seen that use of UsingHorizontalCollisionDetection & UsingVerticalCollisionDetection variable inside DeflectHorizontalCollisions() & DeflectVerticalCollisions().
in DeflectHorizontalCollisions() function returning if UsingHorizontalCollisionDetection is false
but in DeflectVerticalCollisions() i don't found proper use of UsingVerticalCollisionDetection variable
after put same condition like DeflectHorizontalCollisions in DeflectVerticalCollisions (returns function if UsingVerticalCollisionDetection is false) then
Character is floating on water no further snapping to ground.

So i am sure there is something not correct inside code for DeflectVerticalCollisions() or something else

And also i assuming if i enable UsingVerticalCollisionDetection = true so i expect this not going to happen.

Give me correct solutions for this.

Thanks.
 

Attachments

  • Screenshot_1.jpg
    Screenshot_1.jpg
    44.9 KB · Views: 18
  • Screenshot_2.jpg
    Screenshot_2.jpg
    100.3 KB · Views: 19

Justin

Administrator
Staff member
Within the agility pack we have a hang ability that disables gravity and all of the collisions. I did notice some issues with this inside the collision detection part of the code and this sounds related. This will definitely be fixed in version 2.1, but I think that the only change that you need to make is to change:

Code:
            if (m_GroundRaycastHit.distance != 0) {
to:
Code:
            if (UsingGravity && m_GroundRaycastHit.distance != 0) {
 
Top