Make StaticBody3D subject to gravity but not other pyhsics

Godot Version 4.2.2

Make StaticBody3D subject to gravity but not other pyhsics.

This concerns the interaction between two non-player world objects, the player interaction already works, so this is not about the player character.

As far as I can see, the following issues need to be resolved:

  1. unlike player objects, the StaticBody3D has no velocity, so how to make it move according to gravity?
  2. unlike player objects, the StaticBody3D has no is_on_floor(), so how to stop it from moving when it hits the floor?
  3. (And it shouldn’t move halfway through the floor before realizing that it should have stopped.)

Conversely, same question for RigidBody3D (which I’m apparently not allowed to answer as a separate question, so both have to be answered here): it should be subject only to gravity but not to other physics.

The following issues need to be resolved:

  1. unlike for a player body, there is no velocity, so where do I put the gravity?
  2. where do I put the code for detecting collisions with the floor to make it stop falling?

Why to use velocity in static body? And rigid body has many functions to move like velocity, like add_central_force()… etc… It is possible to move static body with velocity with codes

1 Like

StaticBody3D isn’t designed to be moved constantly like that, it’ll be inefficient and not work with a lot of other components, I think this is a situation where you need to ask yourself “why do I need this to do this” and go back to square one and rethink the whole process

You should probably use AnimatableBody3D if you want a static body that moves like this, but otherwise you should use a RigidBody3D or a CharacterBody3D depending on your other needs, a StaticBody3D is specifically for static things, with the useful exception of AnimatableBody3D, but you won’t get any physics interactions with either like this, it just isn’t what it is designed for

1 Like

The body needs to be subject to gravity but not to other physics.

A StaticBody3D is by default subject to no physics.

A RigidBody3D is by default subbject to all physics.

I need the body to be subject to gravity, but not subject to other physics.

A StaticBody3D would need only gravity added - it’s like with moving platforms or revolving doors, except it does not have an uniform motion but a motion accelerated by gravity.

A RigidBody3D would need everything but gravity removed (collision detection still needs to exist, but it may not have any physics effect).

Good point about AnimatableBody3D, I’ll look into that.

You can do this manually, just use custom integration in a RigidBody3D, it doesn’t have to be subject to physics in that way, but you really are asking for something that’s unusual in that way, again I think you need to look at your situation and ask if you’re looking for the right thing

1 Like

So I checked what it needs to do, it definitely needs to be a StaticBody3D.

I guess I can fake gravity by animating position.y with some easing. But finding the right combination of easing, distance and animation duration won’t be easy.

So adding proper gravity would be better.

Do you want to add gravity in static body? If so you can do this

position.y -= 9.8 * delta

Please elaborate

At least it should be a AbimatableBody2D if you want it to behave properly at all

Gravity is an acceleration, not a velocity, and using a magic number is not a good idea.

# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")

var velocity = Vector3(0, 0, 0)

func _physics_process(delta):
		velocity.y -= gravity * delta
		position += velocity

What do you mean by “properly”?

I need it to

  • follow gravity and
  • stop falling on collision with the floor.

but nothing else. It shouldn’t bounce, nor should it cause anything else to bounce by colliding with it. It should just stop on collision.