About AddForce

TickTock

New member
private void JumpAndTurn()
{
AddForce(m_Transform.forward * (-1 * 25) + m_Transform.up * 60);
m_CharacterLocomotion.Torque = Quaternion.Euler(new Vector3(0, 180, 0));
}
I think the player should jump inclined top. But actually he jumped randomly. Is there anything wrong?
20220420-131926_ (1).gif

Invoke in Update()
public override void Update()
{
base.Update();
if (CanStartAbility() == false)
{
StopAbility(true);
}
if (_playerInput.GetButtonDown("Jump"))
{
_animator.SetTrigger(CustomTrigger1);
JumpAndTurn();
StopAbility(true);
}

}
 
Last edited:
Looks like gravity is pulling the player downwards, but with changing magnitude. Seems your force is sometimes added when the character is already falling.
 
Looks like gravity is pulling the player downwards, but with changing magnitude. Seems your force is sometimes added when the character is already falling.
I Add force and stop this ability immediately. I tried AddForce in 1 frame. Same result.
Even though I add the force when the character is already falling. The force is point to the up direction right? So he should jump up if he got an upward force.
 
You add an upward directed force, but it is countered by gravity, and if gravity sets in at different times compared to your force, then you get different resulting vectors.
 
The m_CharacterLocomotion.GravityAmount is accumulate when the character not grounded.
I fix it by clamp it like this. Not perfect but works.
if (m_CharacterLocomotion.GravityAmount < -0.05)
{
m_CharacterLocomotion.GravityAmount = -0.05f;
}
 
You could also disable gravity on your ability, so gravity will be reset while it is active. There are override settings for that on the bottom of the ability editor window.
 
Top