I am looking for a way to make my character to glide. So when a character jumps in the air, it will make him reach the ground at the lower speed. For example, some like this: Knuckles gliding fail - YouTube
I assume your talking about 2D game world?
There are multiple ways to achieve this but here’s one.
When glide is triggered, you can… reduce the downward vector by half.
*added
you can possibly add a variable like
bool isGliding;
to your character. So user can hit certain key while jumping and etc.
then you can reduce the downward vector.
For all of you looking for a nice way, check the code below
using UnityEngine;
public class Glider : BaseBehaviour
{
/// <summary>
/// The speed when falling
/// </summary>
[SerializeField]
private float m_FallSpeed = 0f;
/// <summary>
///
/// </summary>
private Rigidbody2D m_Rigidbody2D = null;
// Awake is called before Start function
void Awake()
{
m_Rigidbody2D = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update()
{
if (IsGliding && m_Rigidbody2D.velocity.y < 0f && Mathf.Abs(m_Rigidbody2D.velocity.y) > m_FallSpeed)
m_Rigidbody2D.velocity = new Vector2(m_Rigidbody2D.velocity.x, Mathf.Sign(m_Rigidbody2D.velocity.y) * m_FallSpeed);
}
public void StartGliding()
{
IsGliding = true;
}
public void StopGliding()
{
IsGliding = false;
}
/// <summary>
/// Flag to check if gliding
/// </summary>
public bool IsGliding { get; set; } = false;
}
Then trigger the StartGliding method when you hold the jump button or whatever