+2 votes

Hello, I am suffering for the second day. There is a large cube made up of smaller cubes that can be destroyed. How to make gravity on this cube? So that you can walk on either side and jump over to the other side? help me please

in Engine by (17 points)

1 Answer

0 votes
Best answer

I've tried in a basic project and it seems to work so you could use an Area with a rectangle collision shape. This will represent the space where there's gravity.

Under the area you set the space_override property to something else that disabled. (See the values https://docs.godotengine.org/fr/stable/classes/class_area.html#enumerations).
You should also set gravity_point to true and gravity_vec to Vector3(0, 0, 0)

EDIT: For completeness. If you want to use a gravity_vector and modify it at runtime, as of Godot 3.3 rc6 it still doesn't work with Bullet so you should use Godot physics instead.

Under Project Settings > General > Physics > 3D > Physics Engine choose GodotPhysics.

by (615 points)
edited by

Forgive me for so many questions, I'm already ashamed to ask. Why does gravityArea.gravity_vec = Vector3 (0,0,1) only work in the _ready function? Neither in physics_process (delta) nor in process (delta) gravity change does not work.

func _ready():
gravityArea.gravity_vec = Vector3(0,0,1)

everything works

func _physics_process(delta):
if Input.is_action_just_pressed("num1"):
    gravityArea.gravity_vec = Vector3(0,-1,0)
    print(gravityArea.gravity_vec)

if Input.is_action_just_pressed("num2"):
    gravityArea.gravity_vec = Vector3(0,0,1)
    print(gravityArea.gravity_vec)

does not work, although it is written in the console output that the vectors are changing

I've tried on my side and you're right it doesn't work if you try to change the vector at runtime. I now remember, I've found a bug in Bullet physics, you should use Godot physics instead.

Under Project Settings > General > Physics > 3D > Physics Engine choose GodotPhysics. It should work now! I just tested it in a small project.

it works, but somehow bad. Can you please give your test project?

Here: https://transferxl.com/08vH9RHMMjxc60

If you run the scene and press space, it will toggle between Vector3(0, -1, 0) and Vector3(0, 1, 0)

Thanks, I figured it out, now everything works. The last question: why can't other bodies interact with this body? For example, I have a kinematic body character, if I touch my ball, the character will jump onto the ball and will not be able to move. Why?

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.