How to make the character always stick to ground no matter the speed and slope?

Hello,

Imagine you have the scenario below


image.png

The player moves forward with a high speed and my question is how do I make him stick to that slope, instead of shooting off in the air. Is it a good solution to change the GravityMagnitude to 10000 of the UltimateLocomotion? Also for some reason even if I do that my fall ability gets activated (min fall height is set to 0.2, so I have to change that to >50 or block the ability). I wonder if there are better ways to do this and make sure the character is completely on the ground.

My idea is to have a couple of those high speed slope zones which will always ground the player unless he hits jump or is in the air before he enters the slope area.

On a separate note: Can classes that inherit from Ability call OnTriggerEnter/Exit only when the ability is active? I know we can do IsActive check, but OnTriggerEnter still won't get called if I'm already in the trigger before I activate the ability. We are going to need OnTriggerStay, but I guess because of performance reasons or something else you haven't added it.
 
Last edited:
For this situation I would create a new ability which adjusts the AbilityMotor to always have the character on the ground.
Can classes that inherit from Ability call OnTriggerEnter/Exit only when the ability is active? I know we can do IsActive check, but OnTriggerEnter still won't get called if I'm already in the trigger before I activate the ability.
OnTriggerEnter/Exit will always be called on all enabled abilities when Unity sends the event.

We are going to need OnTriggerStay, but I guess because of performance reasons or something else you haven't added it.
That's correct - I've always found a workaround instead of needing OnTriggerStay.
 
For this situation I would create a new ability which adjusts the AbilityMotor to always have the character on the ground.

Can you suggest which parameters of the AbilityMotor should be adjusted to achieve such a thing? Or even better if you could send a screenshot underlying the affected parameters.

That's correct - I've always found a workaround instead of needing OnTriggerStay.

I'd be interested in hearing one of your workarounds, the only thing I can think of so far is to have the collider + rigidbody on a child game object of the player, which will get activated once an ability starts and deactivated when it ends, so next time you start it even if you are in the middle of the trigger the collider object will get activated and be detected by the trigger. This will require a bunch of references or events to be fired and I'm always looking for ways that don't require that many dependencies, I mean the OnTriggerStay would solve that with not a lot of extra work.
 
I assume Justin is referring to the AbilityMotor parameter of UltimateCharacterLocomotion, which abilities have access to, and can be used to add a constant motor force to the character. The Drive and Ride abilities in the demo both use this. But from any ability, you can do m_CharacterLocomotion.AbilityMotor = SomeVector3. In your case with the slope, you may want to try adding a constant downwards force.

OnTriggerStay is a perfectly viable option, as long as you're not using it multiple times across multiple objects per frame or anything. As with performance concerns, it's always good to actually try it first and profile it to see if the performance impact is actually significant for your specific use case or not.
 
I assume Justin is referring to the AbilityMotor parameter of UltimateCharacterLocomotion, which abilities have access to, and can be used to add a constant motor force to the character. The Drive and Ride abilities in the demo both use this. But from any ability, you can do m_CharacterLocomotion.AbilityMotor = SomeVector3. In your case with the slope, you may want to try adding a constant downwards force.

I applied -10 on the Y axis and it seems to work, but I can't find any documentation about AbilityMotor. I see it's used in the Drive/Ride ability and I bet if I don't want any force it should stay at 0,0,0 at all times.
OnTriggerStay is a perfectly viable option, as long as you're not using it multiple times across multiple objects per frame or anything. As with performance concerns, it's always good to actually try it first and profile it to see if the performance impact is actually significant for your specific use case or not.
OnTriggerStay isn't available to override in a class that inherits from Ability, so I have to think about other solutions.
 
Yep, you've understood that correctly about AbilityMotor - just setting it back to [0,0,0] when you don't need it any more will do the trick.

That's true - but I can imagine a pretty simple custom script that could handle this stuff using OnTriggerStay. If you want it to be tied to an ability still, you may even be able to do something with CanAbilityStart where it checks a property on a custom script based on OnTriggerStay.
 
Top