Unity record 2.1-action-multi-jump, wall jump, wall slide

The first article and subsequent updates: https://mwhls.top/4450.html , no picture/no directory/format error/more information, please go to the first page to view. Please check mwhls.top
for new updates . Any questions and criticisms are welcome, thank you very much!

Summary: Unity Documentation

Abstract: Realize jumping, wall jumping and wall falling, and rewrite the project.

Reference course: Super new Unity course Use Unity+C# to make 2D games Quick start to actual combat course 2D actual combat course

Prototype crash box 2023/02/13

  • The collision box has a circular shape. After setting, moving left and right will cause the object to rotate. Open the rotation limit of the axis for the rigid body to solve it.

Jump – 2023/02/13

  • In the tutorial, it is realized by adding a circular judgment point on the sole of the foot, but my object is round, and I hope that its lower body can jump when it touches any accessible object, so this circular judgment is not very good.
    • For example, if it is stuck in the seam, the lower body must have contact to get stuck, but because the circular collision is too small, it does not judge the grounding. If it is too large, it can jump in the air.
  • Changed the jump for a few hours today, and one version works great, can jump out of the gap where it gets stuck, and doesn't take off on the wall.
    • Add three colliders, a flat cuboid in the middle, a circle in the lower part, and a narrower cuboid in the bottom foot.
    • All jumps need to be touched by lower to take off.
    • When the middle is in contact, it means hitting the wall and jumping is not allowed unless the foot is also in contact.
    • Use a circular lower to avoid taking off too far, which is a violation.
    • But there is another problem, he can get stuck on the wall, it's not a jumping problem, it's a friction problem.
  • Then I turned off the friction, and found that I could move directly out of the seam, and the jump could be simplified
    • So I deleted my work for several hours, and replaced the foot with an edge with a width of about 0.5. The edge is composed of six points, which is just not too far away from the collision body, and it will not hit the wall because the speed is too fast. jump.
    • Simplify unnecessary things and avoid performance waste.

Unity_05_BetterJump.png

Wall Jump and Wall Drop – 2023/02/14 – 2023/02/15

  • In the middle of the implementation, I found that there were too many scripts and it was difficult to find, so I rewrote the project and introduced the final effect.
  • The whereabouts of sticking to the wall is relatively simple, so I won’t mention it much.
  • You can do multi-stage jumps, multi-stage wall jumps, only wall jumps on the wall, and only jumps on the ground.
  • When you don't press the movement key, you can use the wall jump without horizontal speed on the wall, you can get the highest jump on the wall, and you won't leave the wall because of the horizontal speed.
    • In other words, it is a small trick to cross a high wall.
  • Jumping has a cooldown and is implemented with a coroutine, which involves more complicated judgments below.

Project Rewrite – 2023/02/15

  • This time I rewrote it again. The first time I standardized the naming, the second time, this time, I classified the behaviors and used more complex judgments.
  • Behavior Classification:
    • Previously, PlayerBase was used uniformly to realize movement, animation, and attack.
    • Now movement, attack, and animation are each a class.
    • PlayerBase only stores character information, such as which skills are available and how many times they are left.
  • More complex decisions:
    • All sports now have new judgments: available, number of times remaining, order of execution.
  • A little complaint:
    • I haven’t been doing business for the past few days. I’m doing academics in the morning and Unity in the afternoon and evening. I’ll pay attention tomorrow.
    • But the third episode is the animation switch, it looks like I can start drawing animation!
// 分享一下重写后的跳跃
    public void action_jump(bool keydown_jump, float input_x){
        // condiction
        if (!keydown_jump) return;
        // jump wall
        else if (check_jump_wall()){
            // action
            jump_wall(input_x);
            // animation
        }
        // jump
        if (check_jump()) {
            // action
            jump();
            // animation
        }
    }
bool check_jump(){
    // skill enable?
    if (!player_base.enableSkill["jump"]) return false;
    // touch ground?
    bool isGrounded = check_touch(player_base.transform_dict["FootTouch"].GetComponent<EdgeCollider2D>());
    if (isGrounded) player_base.recoverSkill("jump", "jump_wall");
    // times enough?
    if (!player_base.consume_skill_times("jump")) return false;
    return true;
}

public void jump(){
    // cooldown
    IEnumerator coroutine = player_base.reverse_skill(0.25f, "jump_wall", "jump");
    StartCoroutine(coroutine);
    // action
    rb.velocity = new Vector2(rb.velocity.x, speed_jump_final);
}

bool check_jump_wall(){
    // skill enable?
    if (!player_base.enableSkill["jump_wall"]) return false;
    // touch ground?
    bool isGrounded = check_touch(player_base.transform_dict["FootTouch"].GetComponent<EdgeCollider2D>());
    if (isGrounded) {
        player_base.recoverSkill("jump", "jump_wall");
        return false;
    }
    // touch wall?
    bool isStickWall = check_touch(player_base.transform_dict["MiddleTouch"].GetComponent<EdgeCollider2D>());
    if (!isStickWall) return false;
    // times enough?
    if (!player_base.consume_skill_times("jump_wall")) return false;
    return true;
}

public void jump_wall(float input_x){
    // cooldown
    IEnumerator coroutine = player_base.reverse_skill(0.25f, "move", "jump_wall", "jump");
    StartCoroutine(coroutine);
    // action
    rb.velocity = new Vector2(rb.velocity.x, speed_jump_wall_final);
    move(-input_x);
}</code></pre>

Guess you like

Origin blog.csdn.net/asd123pwj/article/details/129342563