godotengine / godotengine/godot

get_gravity() doesn't update after move_and_collide()

Open
#96,090 4 comments 0 reactions 0 assignees View on GitHub
discussion documentation needs testing topic:2d topic:physics
Dominant language
C++
Stars
117k
Forks
26.8k
PR merge metrics
PR metrics pending

Description

### Tested versions

v4.3.stable.mono.official [77dcf97d8]

### System information

Godot v4.3.stable.mono - Windows 10.0.19045 - Vulkan (Forward+) - dedicated NVIDIA GeForce GTX 1060 6GB (NVIDIA; 31.0.15.5244) - AMD Ryzen 5 2600X Six-Core Processor (12 Threads)

### Issue description

`PhysicsBody2D.get_gravity()` is not updating its value after I call `move_and_collide()`

I'm doing multiple iterations of move_and_collide() in one frame to draw a `Line2D` path in the direction the object will be going and stop at any collision point. The problem is that `get_gravity()`'s value doesn't change at all over the course of the iterations, it stays constant the entire time. I'm using `Area2D` nodes as gravity points, so the gravity value should never be constant for a moving object, and without `get_gravity()` updating I can never actually predict the path my object will take in the future.

If this is intended behavior, there's no indication in the documentation. [It just says](https://docs.godotengine.org/en/stable/classes/class_physicsbody2d.html#class-physicsbody2d-method-get-gravity) `Returns the gravity vector computed from all sources that can affect the body` which is not the behavior I'm observing.

### Steps to reproduce

Use multiple `move_and_collide()` iterations in one frame whilst the object is inside an `Area2D` with `gravity_point` enabled and observe that the value returned from `get_gravity()` is the same for every iteration.

### Minimal reproduction project (MRP)

[get_gravity_bug_godot_4.3.zip](https://github.com/user-attachments/files/16742277/get_gravity_bug_godot_4.3.zip)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.