Agent Jump the Opsive way

Zaddo

Active member
I want to make an agent jump if there is a obstacle in front that has a height between step height and maximum jump height. I create the navigation mesh with a step height greater than the agent's, so that the agent pathfinding goes over these obstacles.

I found a hack solution, but is there a way to do this that utilises the extendibility of UCC?

My current solution is a modification to DeflectHoizontalCollisions in CharacterLocomotion.cs with the below code as an else on the step height check "if (groundPoint.y <= m_MaxStepHeight + c_ColliderSpacing)"

I thought about adding a sensor that does the same checks as DeflectHoizontalCollisions , but that would by a waste of CPU cycles, because it would just redo the same calculations from DeflectHorizontalCollisions.

C#:
                    else if (groundPoint.y <= m_MaxStepHeight * 2f + c_ColliderSpacing)
                    {
                        Debug.Log($"Try to jump: {groundPoint.y}");
                        var jumpAbility = GetAbility<Jump>();

                        // Jump if obstacle is less than max jump height
                        if (jumpAbility != null)
                        {
                            var fallAbility = GetAbility<Fall>();

                            if (!jumpAbility.IsActive && (fallAbility == null || !fallAbility.IsActive))
                            {
                                TryStartAbility(jumpAbility);
                            }
                        }
                    }

 
Last edited:
I thought about adding a sensor that does the same checks as DeflectHoizontalCollisions , but that would by a waste of CPU cycles, because it would just recalculate the same thing in a different method.
I would go that route. You could do a single raycast and you'll never notice it in the profiler.
 
Top