I set up a simple Godot project with just a floor, a player and a box object because I want to test the Fmod 3D spatial sound functions ( a listener and then some sound sources). I put the player a bit up in the air to see if the player would fall down but it does not fall down. And I cannot move the player by applying force. [ApplyCentralForce].

I can move the Player if I attach a script to the topnode (I have the RigidBody3d as a child of a topnode I call Player) and just changing the position of this top node. [GlobalTransform = new Transform3D(
GlobalTransform.Basis,
GlobalTransform.Origin + (input * 10.0f * (float)delta)
);]

So it looks as if there is something wrong with the physics setup? It is as if Axis lock has been set on the RigidBody3D but those are not on.

What is even more frustrating is that I got this to work in an earlier game/test I made where I even have bouncing balls in different colors. I have tried to compare that project to this one but fail to see what I did in that project that made the physics work. I am using the godot physics engine in this latter project which I also did in the previous project - but there I later changed it to the JoltPhysics3D to see how that worked.

Any ideas?

  • xyz replied to this.

    Battern Post your scene setup, i.e. the screenshot of the entire engine window with the rigid body selected and the whole script you use to try to move it.

      xyz

      Great! Here is a picture of the testgame:
      ![
      ](https://)

      Here is the code:

      using Godot;
      using System;
      
      public partial class Player : RigidBody3D
      {
          // Force multiplier to adjust how much force is applied to the player
          [Export] public float ForceMultiplier = 500.0f;
      
          public override void _PhysicsProcess(double delta)
          {
              PlayerMovement((float)delta);
          }
      
          private void PlayerMovement(float delta)
          {
              // Initialize the input vector to zero
              Vector3 input = Vector3.Zero;
      
              // Getting input for the X-axis (left and right movement)
              if (Input.IsActionPressed("move_left"))
              {
                  input.X -= 1;  // Move left
              }
              if (Input.IsActionPressed("move_right"))
              {
                  input.X += 1;  // Move right
              }
      
              // Getting input for the Z-axis (forward and backward movement)
              if (Input.IsActionPressed("move_forward"))
              {
                  input.Z -= 1;  // Move forward
              }
              if (Input.IsActionPressed("move_back"))
              {
                  input.Z += 1;  // Move back
              }
      
              // Normalize the input direction
              if (input.LengthSquared() > 0.0001f)  // Avoid very tiny inputs
              {
                  // Normalize input direction and apply a central force to the player
                  input = input.Normalized();
                  ApplyCentralForce(input * ForceMultiplier * delta);
      
                  GD.Print($"Applied force {input * ForceMultiplier}");
              }
          }
      }

      I hope that is what you need. Looking forward to your response.

      • xyz replied to this.

        Battern

        ApplyCentralForce(input * ForceMultiplier);

          xyz

          Thanks a lot for the feedback but unfortunately it changes nothing. If I understood you correctly that is, you mean like this?:

          using Godot;
          using System;
          
          public partial class Player : RigidBody3D
          {
              // Force multiplier to adjust how much force is applied to the player
              [Export] public float ForceMultiplier = 500.0f;
          
              public override void _PhysicsProcess(double delta)
              {
                  PlayerMovement((float)delta);
              }
          
              private void PlayerMovement(float delta)
              {
                  // Initialize the input vector to zero
                  Vector3 input = Vector3.Zero;
          
                  // Getting input for the X-axis (left and right movement)
                  if (Input.IsActionPressed("move_left"))
                  {
                      input.X -= 1;  // Move left
                  }
                  if (Input.IsActionPressed("move_right"))
                  {
                      input.X += 1;  // Move right
                  }
          
                  // Getting input for the Z-axis (forward and backward movement)
                  if (Input.IsActionPressed("move_forward"))
                  {
                      input.Z -= 1;  // Move forward
                  }
                  if (Input.IsActionPressed("move_back"))
                  {
                      input.Z += 1;  // Move back
                  }
          
                  // Normalize the input direction
                  if (input.LengthSquared() > 0.0001f)  // Avoid very tiny inputs
                  {
                      // Normalize input direction and apply a central force to the player
                      input = input.Normalized();
                      ApplyCentralForce(input * ForceMultiplier);
          
                      GD.Print($"Applied force {input * ForceMultiplier}");
                  }
              }
          }

          I have actually already tried to increase the force (increased the ForceMultiplier to 5000000), but it makes no difference. And the Player should fall down should it not?

          So it looks as if there is something wrong with the physics setup? It is as if Axis lock has been set on the RigidBody3D but those are not on.

          I am sure it is something simple, something obvious that I as a new user of Godot simply misses.

          • xyz replied to this.

            Battern What happens if you just apply large force in X direction in Ready()?
            Also check under Deactivation that none of the flags are enabled.

              xyz

              Thanks again for the suggestions. I added this:

               public override void _Ready()
               {
                   // If the player is sleeping, wake it up
                   if (Sleeping)
                   {
                       Sleeping = false;  // Wake up the RigidBody3D
                       GD.Print("Waking up the player");
                   }
              
                   // Disable sleeping mode to prevent the player from sleeping
                   CanSleep = false;
              
                   // Apply a large force in the X direction to test physics
                   ApplyCentralForce(new Vector3(10000.0f, 0.0f, 0.0f));
                   GD.Print("Applied large force in X direction");
               }

              The "Can sleep" option was on in the inspector and I turned it off there. The object does not seem to sleep because this is the output I get:

              Godot Engine v4.3.stable.mono.official.77dcf97d8 - https://godotengine.org
              Vulkan 1.3.242 - Forward+ - Using Device #0: NVIDIA - NVIDIA GeForce GTX 1060 3GB

              Applied large force in X direction
              Starting: Camera has been set as current.

              I mean, if the object had been sleeping we should have gotten the output "Waking up the player".

              Now, it is getting late here so I have to get back to this tomorrow. Thanks again, and hope to hear from you soon :-)

              • xyz replied to this.

                Battern Try to reproduce it in a fresh minimal project (scene with only a single rigid body and a script that applies force), and post the project here.

                  xyz
                  Hi again. Thanks for all the help.

                  I solved this by painstakingly copying the relevant parts from a testgame I did before. So, I created a new testgame and it now works as expected.

                  Now I can move the player and the player falls. I enclose the scritpt to move the Player. (it needs the delta part in the multiplication).

                  using Godot;
                  using System;
                  
                  public partial class Player : RigidBody3D
                  {
                      // Force multiplier to adjust how much force is applied to the player
                      [Export] public float ForceMultiplier = 50.0f;
                  
                  
                      public override void _Ready()
                      {
                          // If the player is sleeping, wake it up
                          if (Sleeping)
                          {
                              Sleeping = false;  // Wake up the RigidBody3D
                              GD.Print("Waking up the player");
                          }
                  
                          // Disable sleeping mode to prevent the player from sleeping
                          CanSleep = false;
                  
                      }
                  
                      public override void _PhysicsProcess(double delta)
                      {
                          PlayerMovement((float)delta);
                      }
                  
                      private void PlayerMovement(float delta)
                      {
                          // Initialize the input vector to zero
                          Vector3 input = Vector3.Zero;
                  
                          // Getting input for the X-axis (left and right movement)
                          if (Input.IsActionPressed("move_left"))
                          {
                              input.X -= 1;  // Move left
                          }
                          if (Input.IsActionPressed("move_right"))
                          {
                              input.X += 1;  // Move right
                          }
                  
                          // Getting input for the Z-axis (forward and backward movement)
                          if (Input.IsActionPressed("move_forward"))
                          {
                              input.Z -= 1;  // Move forward
                          }
                          if (Input.IsActionPressed("move_back"))
                          {
                              input.Z += 1;  // Move back
                          }
                  
                          // Normalize the input direction
                          if (input.LengthSquared() > 0.0001f)  // Avoid very tiny inputs
                          {
                              // Normalize input direction and apply a central force to the player
                              input = input.Normalized();
                              ApplyCentralForce(input * ForceMultiplier);
                  
                              GD.Print($"Applied force {input * ForceMultiplier * delta}");
                          }
                      }
                  }

                  Thanks again. It feels good to know that there are people out there that respond when you have a problem. That in itself I think is very important for Godot to grow. Especially since there are not that many tutorials out there for these basic things.

                  • xyz replied to this.

                    Battern (it needs the delta part in the multiplication)

                    It doesn't really but that's for another topic.

                      xyz
                      I thought it was needed to adapt to different speeds on the PC. But i took the delta away and I thought that would make the Player shot of the scene because the force would be so much increased. But I was wrong. It behaves in much the same way.

                      Definitely a lot to learn!