godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
89.23k stars 20.23k forks source link

Physics Tutorial suggests using StaticBody2D for moving platforms #33593

Closed nightblade9 closed 4 years ago

nightblade9 commented 4 years ago

If you read this awesome tutorial, under StaticBody2D it suggests:

Example uses for StaticBody2D: Platforms (including moving platforms), Conveyor belts, Walls and other obstacles

Unless I'm missing something, static bodies can't be used for moving platforms. The official platformer tutorial uses one (and modifies the transform), but that just seems like the wrong approach.

Am I missing something, or is this a documentation error?

+@eon-s

KoBeWi commented 4 years ago

They have constant_linear_velocity property, which makes them work like conveyor belts and together with moving the body it simulates the moving platform. So documentation is right here. It's just not the only way to make moving platforms.

groud commented 4 years ago

Indeed, as stated two lines above in the documentation:

However, it can impart motion or rotation to a colliding body as if it were moving, using its constant_linear_velocity and constant_angular_velocity properties.

So this is indeed not a mistake. (The "were" instead of "was" is a mistake though ^^).

nightblade9 commented 4 years ago

They have constant_linear_velocity property, which makes them work like conveyor belts and together with moving the body it simulates the moving platform.

I don't understand. Setting constant_linear_velocity doesn't move the body itself, it only moves anything that collides with it. So it creates a conveyer belt, yes, but not a moving platform.

Maybe you can throw together a quick sample project to illustrate what you mean. I don't see how a static body can be configured to create a moving platform.

groud commented 4 years ago

I guess you have to both move the body and set this value. This basically allow a kinematic body to stay the static body, even if the static body is moving (otherwise it would slip off the platform).

nightblade9 commented 4 years ago

This basically allow a kinematic body to stay the static body

Sorry for being dense, I don't understand what you mean by this.

When I read the physics tutorial, I assumed you have simply a StaticBody2D as the root node, and some combination of settings makes it a moving platform.

Perhaps the tutorial could be more verbose/detailed, or link to a separate tutorial on how to achieve this? From searching the web (and figuring out a solution myself), there seem to be quite a number of different approaches someone can take.

groud commented 4 years ago

Here is a sample project with two moving platforms, you can see the difference by yourself. :) StaticbodyPlatform.zip If you need more precise information and feel like the documentation lacks information about that, please open an issue in the godot docs repository.