![]() velocity.y = move_and_slide(velocity, FLOOR_NORMAL, true).y So, we can simply say yes or rather true. The third argument of the move_and_slide method asks you if the character should stop on slopes. To prevent this, we just need to pass another argument to the move_and_slide call. Since we are applying gravity, Godot tries to solve the vertical collision by sliding the character horizontally. You can see that the character still slides a bit if we stop in the middle of the slope. We only use the vertical remainder to allow our character to “climb” the slope: velocity.y = move_and_slide(velocity, FLOOR_NORMAL).y So to prevent this remainder to overwrite our horizontal velocity…we simply don’t assign the horizontal remainder. Godot tries to find a way to make your movement possible and the remainder is what Godot couldn’t transform into a valid movement. The remainder of the movement is what remains from a collision. We are getting the remainder of the movement and applying as our updated velocity. Since the move_and_slide method returns the remainder of the movement by using this line: velocity = move_and_slide(velocity, FLOOR_NORMAL) If event.is_action("left") or event.is_action("right"):ĭirection.x = Input.get_action_strength("right") - Input.get_action_strength("left") Velocity = move_and_slide(velocity, FLOOR_NORMAL) This is the code I’m using for this character. You can’t see it just by watching, but as soon as I stopped in the slope on the left, I released the keyboard, all the movement afterward is the remainder of the character trying to climb the slope. Also…that’s not all, look how it slides if you stop in the middle of the slope. Notice how the character seems to fly for a while when it comes from a slope to a flat floor. OK, you’re probably using KinematicBody2D already, right? And you are probably using move_and_slide as well right? Here is the problem, this is how move_and_slide handles slopes: But fear nothing, in this post, you’ll understand how to overcome them. One of those challenges has a name and shape: slopes. ? I think it's a pretty good overview of the topic specifically applied to its use in games.Making platform movement is always a challenge, you have all sorts of nuances, tricks, and wizardry to achieve what you’re looking for. Hopefully that clarifies it at least somewhat questions 1-3.Īs for #4, what is melting your brain about vectors? Have you read this: move_and_slide(), however, takes the pre-delta velocity (yes, this can be confusing). Fun fact: move_and_slide() calls move_and_collide() internally to process the movement.īoth take a vector for the movement, but move_and_collide(), being the more basic method, is just the frame-based (ie multiplied by delta) movement vector. For this reason, it can't return a collision, so you need to use the get_slide_collision() method to retrieve the details. However, because it slides, it's possible for there to be more than one collision in a frame (think when you hit a corner between the floor and the wall. Move_and_slide() was designed as a special case, because a common use case was to calculate a slide vector along the collision. If a collision happens, it returns a collision object containing the details. It attempts to move the body along the given vector, stopping if it collides with another body. Move_and_collide() is the basic movement method for kinematic bodies.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |