Opposing forces(cancel each other )

Hey Justin basically , i am implementing a Glide ability into the controller and it works amazing but i have 1 problem, When the cahracter hits the ground he gets shot through it because he has high velocity,

Basically, to glide i am getting the locallocomotionvelocity on the Y axis and i am inverting it and adding it as a force , using ADDFORCE();

How can i negate the concatenation of the character's velocity, would i not be correct in saying the character's velocity should = 0 because the forces are equal but opposite?


Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Opsive.UltimateCharacterController.Character.Abilities;
using Opsive.UltimateCharacterController.Motion;
using Opsive.UltimateCharacterController.Character;
using Opsive.UltimateCharacterController.Utility;
using Opsive.UltimateCharacterController.Events;




public class Glide : Ability {

    float gravitymodifier = 0.4f;

    public float startglidegravitymodifer = 0.1f;

    float maxmodifiervalue = 0.4f;

    
    public float decreasetime;

    UltimateCharacterLocomotion loco;
        private UltimateCharacterLocomotionHandler m_Handler;

    bool toggled;
        private RaycastHit m_RaycastResult;

        float temptime;

 public override void Awake()
        {
            base.Awake();
            
            m_Handler = m_GameObject.GetCachedComponent<UltimateCharacterLocomotionHandler>();
            

            EventHandler.RegisterEvent<bool>(m_GameObject, "OnCharacterGrounded", OnGrounded);
            

          
        }


         private void EnsureAirborne()
        {
            if (!m_CharacterLocomotion.Grounded) {
                return;
            }

            StopAbility(true);
        }

public    override void Start(){
    loco = this.m_GameObject.GetComponent<UltimateCharacterLocomotion>();
    Debug.Log(loco.gameObject.name);


}

protected override void AbilityStarted()
        {
          

            base.AbilityStarted();
        //loco.GravityModifier = startglidegravitymodifer;

            
            temptime = 0;
          
          
        
        }
/// <param name="force">Was the ability force stopped?</param>
        protected override void AbilityStopped(bool force)
        {
            base.AbilityStopped(force);
        loco.UseGravity = true;

        //loco.GravityModifier = 0.4f;
                   Debug.Log(loco.GravityModifier + "out");
                  // loco.AddRelativeForce()




          
        }

        public override bool CanStartAbility()
        {

            // An attribute may prevent the ability from starting.
            if (!base.CanStartAbility()) {

                return false;
            }
            if (loco.Grounded) {
//                Debug.Log("called");
                return false;
            }

        //    //The character can't jump if they aren't on the ground nor if they recently landed.
        //     if (!m_CharacterLocomotion.Grounded || m_LandTime + m_RecurrenceDelay > Time.realtimeSinceStartup) {
        //     //Debug.Log("calledjump");

        //         return false;

        //     }
            

            
          

          
          //  Debug.Log("calledjump start");


            return true;
        }




         public override bool CanStopAbility()
        {
            
            if(loco.Grounded){

                StopAbility(true);
                return true;

                
              
            }else{
                return false;
            }
        }

      

        public override void UpdatePosition()
        {
            EnsureAirborne();



            var force = 0f;
            var deltaTime = m_CharacterLocomotion.TimeScaleSquared * TimeUtility.FramerateFixedDeltaTimeScaled;
           
                force = (loco.LocalLocomotionVelocity.y *-1);
                Debug.Log(force);
              
          

            if (force != 0) {
               // AddForce(m_CharacterLocomotion.Up * force, 1, false, false);
               Vector3 tift = new Vector3(0,force,0);
               // AddRelativeForce(tift);
               loco.AddForce(tift);

              
     
        

                
                
            }
        }




 public override void UpdateAnimator()
        {
//            Debug.Log(loco.Velocity);
            //loco.Velocity = Vector3.zero;


            
            if(loco.Grounded || loco.GravityModifier > maxmodifiervalue){

                StopAbility(true);
            }
            

                
              
            

              temptime += Time.fixedDeltaTime;
//              Debug.Log(temptime);
              if(temptime >= 4f){
                  StopAbility(true);
              }
            

//             // Set the Float Data parameter for the blend tree.
//                    if(!toggled){

//     }


//     if(loco.GravityModifier < maxmodifiervalue){
// //    Debug.Log(loco.GravityModifier);

//     loco.GravityModifier +=  temptime ;

    
    

//     }
    


        }



    private void OnGrounded(bool grounded)
        {
            if (grounded) {
                if (IsActive) {
                    StopAbility(true);
                }
              
            }
        }
 
If you want to completely resent all momentum you can call CharacterLocomotion.ResetRotationPosition. If you still want there to be some momentum then I would modify the ApplyPosition method and adjust the MoveDirection based on the amount of movement that you still want to have.
 
Top