Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add properties to CharacterBody for more move_and_slide options #2982

Closed
fabriceci opened this issue Jul 11, 2021 · 6 comments
Closed

Add properties to CharacterBody for more move_and_slide options #2982

fabriceci opened this issue Jul 11, 2021 · 6 comments
Milestone

Comments

@fabriceci
Copy link

fabriceci commented Jul 11, 2021

Describe the project you are working on

A 2D platformer.

Describe the problem or limitation you are having in your project

They are weird behaviour with the current logic,move_and_slide is defined as such:

move_and_slide is intended to simplify the collision response in the common case where you want one body to slide along the other. It is especially useful in platformers or top-down games

This method allows beginners to build games that require "common" physics very easily, more than many engines, that's a gem. However I was not satisfied by the current behaviour and I tried to experiment to see what can be improved.

  1. Moving platform

They are many issues with moving platform, as fixing those issues is useful in the current version, I will not describe what and why as I did a PR for that #50314

  1. Move and slide logic

move and slide makes a projection into the collision normal, so it moves and slide :) however it will change the velocity according to the projection and that will lead to bad behaviours.

  • when you project and change the velocity you lose the original direction
  • when you project and change the velocity you change the length

I have a lot of examples but here are few to illustrate the idea:

a)

If you walk into a slope the body will slowdown, however, to understand well, it's not the method that slowdown the body but the developer because we usually set the x component of the velocity.

However if the slope is too steep, move_and_slide will increase the y a lot, and so, as the length of the velocity returned by the method will be bigger, the body will accelerate and will start to fly and the end of the slope

steep

b)

The body accelerates on the ceiling which is not physically correct (this can also stop the motion as in the following gif):

acceleration 1

As the velocity slide, this will block the motion sometime:

JUMP current

  1. Don't cover some basic behaviour

Describe the feature / enhancement and how it helps to overcome the problem or limitation

  1. For the logic, the idea is to no more change the velocity by the projection (see code for details)

  2. I tried to list (and asked for feedbacks in few platforms) to see what options can cover the majority of the needs, here are the ideas I find relevant:

  • Constant speed on the floor: as requested from a long time, this force the body to move in a constant speed in slope
  • Move on floor only: currently you can move on walls, same most of the time you don't want that
  • Exclude layer for moving platforms: currently you have to follow when you are in a moving body
  • Slide on the ceiling: if you want the ceiling stop the body, or not (current behaviour).

notes:

  • they are options, you can turn them on or not
  • in 4.0 there is no more parameter in move_and_slide, they are properties

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

I made of POC of this proposal in GDScript:

If this enhancement will not be used often, can it be worked around with a few lines of script?

Not in few lines and not easy.

Is there a reason why this should be core and not an add-on in the asset library?

it's core

GIF after this proposal

acceleration now
Jump now
demo

@pouleyKetchoupp pouleyKetchoupp added this to the 4.0 milestone Jul 13, 2021
@pouleyKetchoupp pouleyKetchoupp changed the title Improve (and fix) move_and_slide for 4.0 Add properties to CharacterBody for more move_and_slide options Jul 13, 2021
@pouleyKetchoupp
Copy link

I agree with the concept and the proposed options.

It's in phase with the plan for 4.0, and it's the reason why physics nodes have been reorganized to have a specialized node for characters (proposal #2184).

Detailed comments about specific options:

Constant speed on the floor: as requested from a long time, this force the body to move in a constant speed in slope

Yes, this is a recurring demand and it was already on my radar. Probably disabled by default, but I'm not completely sure about that.

Move on floor only: currently you can move on walls, same most of the time you don't want that

Sounds like a good idea. The current behavior does lead to situations that look buggy when climbing up slopes, so this should probably be the default behavior.

Exclude layer for moving platforms: currently you have to follow when you are in a moving body

Seems useful as well, since there's currently no option to disable the effect of moving platforms (which also includes other characters) and that seems the most flexible way.

Slide on the ceiling: if you want that the ceiling stop the body, or not.

It is a known issue (godotengine/godot#20593). As commented in that issue, it could be done in user script, but with the new design an option would be great since it does seem like a common case. I would probably make it slide by default.

Also as an alternative, it could be a threshold to allow for more flexibility (as proposed in godotengine/godot#20593 (comment)), so it would be allowed to slide past a certain angle and bump if the ceiling is flat enough.

@Janders1800
Copy link

Same for 3D.

@AttackButton
Copy link

AttackButton commented Jul 25, 2021

About the:

Move on floor only: currently you can move on walls, same most of the time you don't want that

This already exists with the floor_max_angle paramenter of move_and_slide. I like the idea of the floor max angle because games that use a lot of slopes and loops like Sonic can be made so much easier with it.

  • For example, in a Sonic like game you can increase the floor_max_angle as the speed increases.
  • And if you want the character of a game to walk strictly on a horizontal floor, just set the floor_max_angle property to 1.0º or 2.0º all the time.

Why not make the 1.5º or maybe 2.0º as the default value of floor_max_angle property of move_and_slide to solve this? At this moment it is 0.785398 (45º). I really think move_and_slide doesn't need another property for this and floor_max_angle is a really good concept that needs to stay to be controlled by the game designer.

Another question, the snap vector of the move_and_slide_with_snap function will stay in the new version?

@fabriceci
Copy link
Author

This already exists with the floor_max_angle

The parameter floor_max_angle is only used to determine if you are on a floor, a wall or a ceiling. If you set the floor max angle to 1° you you still be able to walk on "wall". move on floor only will prevent you to be able to move on wall (if enabled).

the snap vector of the move_and_slide_with_snap function will stay in the new version?

This proposal in only about adding/fixing things, all the current options remain.

But FYI, as everyone doesn't know that, move_and_slide_with_snap and move_and_slide are merged in one method in 4.0. Snap becomes a property, as well as all the other argument. You will simply call the function like this move_and_slide() and set the property in code or in the editor (see screen of my work in progress)

Screenshot 2021-07-26 at 10 16 23

@AttackButton
Copy link

Cool! Nice work, man.

@akien-mga
Copy link
Member

Implemented by godotengine/godot#51027.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants