Topview Logo
  • Create viral videos with
    GPT-4o + Ads library
    Use GPT-4o to edit video empowered by Youtube & Tiktok & Facebook ads library. Turns your links or media assets into viral videos in one click.
    Try it free
    gpt video

    Stairs and Lerp - 3D FPS in #gamemaker

    blog thumbnail

    Introduction

    In the world of video games, stairs can present a unique problem for developers. When we consider how characters move, it becomes evident that they don't actually walk on the ground but rather glide over it. This creates a challenge when a player glides into an elevation, like a step. To distinguish between a wall and a step, developers need to implement some form of logic.

    In a previous development log, collision code was established to handle walls during jumping and falling. The next step is to address the question: how do we determine whether a collision is with a stair or a wall? The solution can vary depending on the game, but one common approach is to make stairs into invisible ramps. By converting stairs into inclines, players can glide up seamlessly. However, this method has several drawbacks. It requires extra levels of design complexity, as every staircase and minor elevation would need to be converted into ramps. Additionally, it creates a disconnect between the visual model and the underlying collision detection.

    A more efficient approach is to set a maximum step size. This value dictates how high a character can step up, effectively allowing the game to differentiate between a step and a wall. When a player collides with an object, the game checks if moving up by the specified step size results in the character no longer colliding. If this is the case, the game moves the character up accordingly.

    However, an issue arises with this snapping effect, where the character's movement may appear jittery due to the set amount of upward displacement. A more refined technique would involve using vectors or raycasting to ensure players smoothly transition to the new height. An alternative solution is to apply linear interpolation (commonly known as lerp) to the camera height, which provides a smoothed transition.

    What is Linear Interpolation?

    Linear interpolation (lerp) is a method used to smooth out changes by gradually transitioning a value from one point to another. To apply lerp, three values are necessary:

    • Value A: The current value.
    • Value B: The target value.
    • Lerp Amount: Typically a percentage between 0 and 1.

    For example, if Value A is 0, Value B is 100, and the lerp amount is 0.3, the lerp function would return 30. This means that rather than abruptly changing the camera's height, the game can incrementally adjust the height over time, making for a smoother transition.

    In summary, when a player collides with an object, the game checks if moving up by the defined step height resolves the collision. If it does, linear interpolation is then utilized to adjust the camera height smoothly, eliminating the snap effect. This provides the functionality needed to handle stairs within the game smoothly.

    Now that we have established a collision system capable of managing player actions such as walking, jumping, falling, and climbing stairs, there is but one challenge left to conquer—the ability to swim!


    Keyword

    • Stairs
    • Lerp
    • 3D FPS
    • Collision detection
    • Maximum step size
    • Linear interpolation
    • Game development
    • Camera height
    • Glide movement

    FAQ

    Q: What is the main issue with stairs in video games?
    A: The main issue is that characters glide over surfaces rather than walking, complicating how they interact with elevations like stairs as they may not distinguish between walls and steps effectively.

    Q: What is one method developers use to handle stairs?
    A: Developers often convert stairs into invisible ramps, allowing characters to glide up inclines instead of stepping, although this approach can increase level design complexity.

    Q: How does setting a maximum step size help in collision detection?
    A: Setting a maximum step size allows the game to determine how high a character can step, differentiating between a step and a wall when collisions are detected.

    Q: What is linear interpolation (lerp)?
    A: Linear interpolation (lerp) is a method used to smoothly transition between values over time instead of making an abrupt change, which can help avoid snapping effects in camera height.

    Q: How does the lerp function work?
    A: The lerp function requires three values: the current value (A), the target value (B), and a lerp amount (a percentage). It calculates an intermediate value based on these inputs to create a smooth transition.

    One more thing

    In addition to the incredible tools mentioned above, for those looking to elevate their video creation process even further, Topview.ai stands out as a revolutionary online AI video editor.

    TopView.ai provides two powerful tools to help you make ads video in one click.

    Materials to Video: you can upload your raw footage or pictures, TopView.ai will edit video based on media you uploaded for you.

    Link to Video: you can paste an E-Commerce product link, TopView.ai will generate a video for you.

    You may also like