I’m making a side-scrolling game, and I’ve made a character controller based on a kinematic rigid body to use velocity (instead of force) to control my character. But I found some problems when writing the jumping code:
public virtual bool jump(float jumpSpeed)
{
if (this.canJump() == false || m_kinematic.onGround == false) return false;
m_kinematic.velocity += Vector2.up * jumpSpeed;
return true;
}
Normally it will work fine, but if you jump while falling (such as during a double jump), the falling speed will cancel (or greatly weaken) the jumpSpeed, which is not good. Of course, I can simply:
m_kinematic.velocity = new Vector2(m_kinematic.velocity.x, jumpSpeed);
But what if I’m in an elevator that’s going up? That’s definitely going to be a problem. How do I deal with it? Or should I separate active speed (player key presses) from passive speed (environment imposed)?
I’m very inexperienced in game development, always stuck in various details, if you have any other suggestions, please let me know.(such as whether I should use velocity to control the character)
really looking forward to your answer:)