godotengine / godotengine/godot
Physics joints solve for last frame's position when node is controlled inside a script.
- Dominant language
- C++
- Stars
- 117k
- Forks
- 26.8k
- PR merge metrics
- PR metrics pending
Description
### Tested versions
4.2.1 stable, Godot Physics and Jolt Physics
### System information
Windows 11 version 10.0.22631 - Vulkan (Forward+) - dedicated AMD Radeon RX 7900 XTX (Advanced Micro Devices, Inc.; 31.0.22023.1014) - AMD Ryzen 7 7800X3D 8-Core Processor (16 Threads)
### Issue description
When a joint is connected to a script-controlled physics body (CharacterBody, RigidBody in kinematic mode), and a RigidBody node, the joint solver solves for the script-controlled physics body's last position, rather than current position.
The RigidBody solves to be 1 frame behind the CharacterBody
https://github.com/godotengine/godot/assets/38119387/b5e87b8e-a389-48ab-9e51-f6b2b93be854
Here I have set the CSGBox's position to be `-velocity * delta` (last frame's position), where it matches the RigidBody. I have not adjusted the Camera's position, so you can tell the CSGBox and RigidBody are following 1 frame behind.
https://github.com/godotengine/godot/assets/38119387/6255ef5e-c951-45ea-9bff-bcf297dbcdf4
I believe this is because _physics_process is run after the physics tick, and after joints have solved.
### Steps to reproduce
Connect a RigidBody to a CharacterBody using a physics joint. Move CharacterBody.
### Minimal reproduction project (MRP)
[minimal.zip](https://github.com/godotengine/godot/files/14110845/minimal.zip)
White cube is the CharacterBody. Red sphere is the Rigidbody. Camera is affixed to the CharacterBody.
Contributor guide
Research direction
Start by running the linked minimal.zip project and reproducing the one-frame lag between the CharacterBody and RigidBody connected by a physics joint. Read the issue's description of _physics_process timing and compare the joint solver's result with the CharacterBody's current and previous positions; done means the connected RigidBody follows the script-controlled body without the frame delay.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- game-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100