1
\$\begingroup\$

My First Person Controller (CharacterBody3D) currently has no momentum at all. By the way, I measure my movement speed in the debug panel (hotkey ~) with velocity.length() and when I get pushed by one of the platforms (see this video), my speed stays at 0 while I'm being pushed, which isn't how it supposed to be. What would be the best way to add a momentum/inertia feature and measure my current speed at all times?

enter image description here

Source: https://github.com/CryptoMares/FPS-Player-Controller

Thanks!

\$\endgroup\$
9
  • \$\begingroup\$ You should be able to fix the platform with platform_on_leave. I do not know about the wall case (I haven't tested, I don't have much time to look into it now). However, the documentation mentions platform_wall_layers which might be a solution (idk). Addendum: It might also be that the code is not recognizing the platform as a platform. If you are moving it directly, use a AnimatableBody3D with sync_to_physics, if it is nested try other types of body (I recall running on some issue like that). \$\endgroup\$
    – Theraot
    Commented Apr 29 at 9:24
  • \$\begingroup\$ Sorry for the newbie question, but I've set the AnimatableBody3D like this, but I get no collision at all now. What am I doing wrong? \$\endgroup\$
    – ThetaJones
    Commented Apr 29 at 12:05
  • \$\begingroup\$ The picture is not loading for me. However, no collision at all implies you can't even have the character standing on it, which I would guess it is a matter of setting the collision layers. Also, you can enable visible collision shape in the debug menu to see if the colliders are positioned correctly while running the game from the editor. \$\endgroup\$
    – Theraot
    Commented Apr 29 at 12:09
  • \$\begingroup\$ Alternative link to that same image No idea what to do with the collision layers yet, but thanks for the tip! \$\endgroup\$
    – ThetaJones
    Commented Apr 29 at 12:16
  • \$\begingroup\$ Ok, so you have a CSGBox3D with the body as a child. I'd assume the CSGBox3D does not have physics enabled, to let the AnimatableBody3D handle the collision. However, the CSGBox3D has a script, which makes me think in this case the AnimatableBody3D is not moving itself, but the CSGBox3D is moving. This is what I meant by having the AnimatableBody3D nested, I had issues with this before, in that configuration try StaticBody3D or CharacterBody3D for the platform. However, if you can, do it the other way around: put the CSGBox3D inside the AnimatableBody3D and move it. \$\endgroup\$
    – Theraot
    Commented Apr 29 at 12:24

1 Answer 1

0
\$\begingroup\$

You can use AnimatableBody3D to implement static bodies that can be moved around, automatically updating their own linear and angular velocities for affecting colliding objects. Or, you can set manually such velocity values for StaticBody3Ds if you have static bodies that resemble moving surfaces (rolling tapes, etc.) This will ensure a consistent physics simulation and enable the momentum effects you described when combining an appropriate floor_snap_length value.

\$\endgroup\$
7
  • \$\begingroup\$ This is a First Person Controller, so it's in 3D. How would you translate this concept into 3D? Also, please try my controller out in Godot, if it's not too much trouble. \$\endgroup\$
    – ThetaJones
    Commented Apr 29 at 7:49
  • \$\begingroup\$ That's the same in 3D. I see you're using a CharacterBody for the player, this should be included in your question rather than leaving it to an external code repository. \$\endgroup\$
    – liggiorgio
    Commented Apr 29 at 8:08
  • \$\begingroup\$ Ok thanks. Even though I don't really understand — I will keep trying. What about the fact that my velocity isn't being calculated while I'm being pushed by one of the platforms? link \$\endgroup\$
    – ThetaJones
    Commented Apr 29 at 9:04
  • \$\begingroup\$ Static bodies are static for the engine. That's why they have constant_*_velocity properties so that you can emulate them moving around from a physics perspective: this makes them affect other colliding bodies' momenta. Your character body also snaps to the floor, so if you want it to be "launched" when pushed by a moving platform, you have to work around its snapping and friction properties. (Check my edited answer.) \$\endgroup\$
    – liggiorgio
    Commented Apr 30 at 10:18
  • \$\begingroup\$ Thank you! I will look into this and report back. \$\endgroup\$
    – ThetaJones
    Commented May 1 at 10:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .