As shown in the figure, the capsule continues to move in the +x direction (the direction of another collision object).
The problem is that gravity does not work properly in this case.
[191135-스크린샷97.png|191135]
Rigidbody.Gravity was basically used. If there is no collision except for the floor, it works correctly.
Therefore, it is not a solution to use a high value of custom gravity.
As a result of analyzing Rigidbody.Info,
- Move the Capsule in the +x and +y directions.(OK)
- Collides with another object.(OK)
- Rigidbody.velocity.x changes to zero. (OK)
- Rigidbody.velocity.y changes close to zero. (Why?)
I ask for help like this due to lack of knowledge.
It can be awkward because I used a translator.
public class Movement : MonoBehaviour
{
Vector2 direction = Vector2.zero;
Vector3 velocity = Vector3.zero;
Rigidbody rb;
[SerializeField]
private float speed = 3f;
[SerializeField]
private bool isJumpPressed;
[SerializeField]
private float jumpHeight = 2f;
private void Awake()
{
rb = GetComponent<Rigidbody>();
}
private void FixedUpdate()
{
Move();
Jump();
}
private void Jump()
{
if (!isJumpPressed) return;
velocity.Set(velocity.x, jumpHeight, velocity.z);
rb.velocity = velocity;
}
private void Move()
{
velocity.Set(direction.x * speed, rb.velocity.y, 0f);
rb.velocity = velocity;
}
#region Input Events
public void OnMove(InputAction.CallbackContext value)
{
direction = value.ReadValue<Vector2>();
}
public void OnJump(InputAction.CallbackContext value)
{
if (value.performed)
isJumpPressed = true;
else
isJumpPressed = false;
}
#endregion
}