appsinacup / godot-rapier-2d Goto Github PK
View Code? Open in Web Editor NEWGodot Rapier 2D – C++ Godot GDExtension that integrates the Rapier 2D physics engine
Home Page: https://appsinacup.com
License: MIT License
Godot Rapier 2D – C++ Godot GDExtension that integrates the Rapier 2D physics engine
Home Page: https://appsinacup.com
License: MIT License
Right now the plugin isn't cross platform deterministic. The issues could be from:
From my investigation the plugin uses .length(), as it uses Vector2 of godot-cpp, which in turn uses sqrt, which isn't cross platform deterministic.
Need to investigate other possible things as well. After asking on chat.godotengine.com about it, got some helpful tips as well:
AThousandShips:
Then it isn't related to the extension code itself, and the only possible cause is the cross-platform differences in sqrt etc.
As the built-in types like those are entirely self-contained on extensions, for performance reasons
But I'd suggest just testing the output of various simple operations across platforms just to see, generate a bunch of vectors for example and run the operations on them on both systems, just create a data file to store them in and load them on both machines
If they yield the same results then it's going to be the way you've translated this library to the language in question, it's easy to make mistakes when translating between languages
And of course make sure you're actually setting up a test that ensures determinism, because floating point mathematics isn't deterministic when out of order due to rounding, so it's important that your testing conditions are actually such that they test for determinism
And, and this is really important, make sure the data for the tests are dynamic, no compile time tests, it has to be loaded, because that's a classic trap
Especially with floating point math compile time and runtime is a mess
Static body constant speed (conveyer belt) doesn't work
Steps to reproduce the behavior:
Create a one way platform
Create a rigidbody with a shape
The body should have it's speed changed by the static body
Environment (please complete the following information):
OS: macOS
Version v0.3
Godot Version v4.2
Type simd single
I have tried this with the box shaped and pill shaped character colliders and with the same result. It gets stuck when trying to jump and holding movement towards the wall.
CharacterBody collider seems to penetrate into the wall.
Never mind. I think I'm just a git and programed myself into a corner or something... I'm going to have to just start the game over I guess because I can't seem to get it right. So, I think it's fine I just didn't make a unique collider... but that's not what is wrong in my main game so I dunno... probably just me being shit even though I've done this for a couple of decades.
Describe the bug
On applying impulse or force on RigidBody2d by a CharacterBody2d the body moves out of the scene through walls.
Without rapier extension it works fine.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Even after setting infinite impulse to false and making the collision walls (StaticBody2d with CollisionShape2d) the RigidBody2d should not phase through the wall / scene.
Screenshots
(video attached)
Reference project:
https://github.com/souvikinator/test-gdt
Environment (please complete the following information):
Disable Collision is working if using the Godot physics engine.
When using rapier2d, use PinJoint2D to connect two Rigidbody2D and they will collide with each other even when Disable Collision is checked.
Thank you for your excellent work!
Describe the bug
Project won't open after installing any of the plugin versions from asset store and reloading the project, no crash log files that i could find from godot engine.
To Reproduce
1 open godot 4.2.1
2 create a project
3 install godot rapier from asset store
4 restart engine or reload project
5 crashes
Expected behavior
shouldnt crash
Environment (please complete the following information):
Godot v4.2.1.stable - Windows 10.0.22631 - GLES3 (Compatibility) - NVIDIA GeForce RTX 4060 (NVIDIA; 31.0.15.5123) - Intel(R) Core(TM) i3-10100F CPU @ 3.60GHz (8 Threads)
Example project(zip)
New project
on ios I need to add info.plist files otherwise release build won't work.
Describe the bug
Calling get_overlapping_areas()
on Area2D can return array with reference to self instead of other Area2D
To Reproduce
Steps to reproduce the behavior:
_physics_process
call get_overlapping_areas()
on Area1. It returns [Area2]get_overlapping_areas()
on Area2. Also returns [Area2]Expected behavior
Calling Area1.get_overlapping_areas()
should return [Area2]] (which it does)
Calling Area2.get_overlapping_areas()
should return [Area1]] (which it does not)
Environment (please complete the following information):
I think this one is legit. So in the Godot phys engine, objects with zero linear damp will go in their direction forever. Likewise, zero angular damp should spin forever. In Godot Rapier both linear and angular slow over time with zero damp, tossing the first law of motion out the window like a baby with the bath water... or something.
Anything that moves in this project exhibits the behavior: https://github.com/GeminiSquishGames/Rapier2Dbug
Seems like Replace rather than Combine mode helps, but this isn't how Godot works. Pretty sure zero damp should let the object move forever unless acted upon in order to simulate it right... I think.
Describe the bug
Raycasts sometimes tunnel through polygon shapes with the "Solids" build mode.
To Reproduce
I've attached a project demonstrating the behavior. Simply move the mouse around to see the difference between raycasting against solids vs segments.
Expected behavior
Raycasts against polygons with build_mode = BUILD_SOLIDS
should behave approximately the same as raycasts against polygons with build_mode = BUILD_SEGMENTS
.
Screenshots
Blue = Raycast result against segments
Orange = Raycast result against solids
Environment
It's hard to describe what I'm experiencing. All I can say is I had a working asteroid-like game going, and now very few things work as they do with the default.
The bullet speeds are much slower and aren't registering hits.
I spawn asteroids in with a random linear_velocity and angular_velocity set so they distribute that as they move around, but now they simply have a constant rotation and are not distributing the angular velocity properly, or at all really. As if they are on a constant torquing motor and angular velocity keeps the same value without dampening. This is the SMID faster version. But it seems like no rotation happens in slower ED version.
My player rigid body would point at the mouse cursor but it goes out of sync now when things kind of collide but get stuck to it. It seems better but still happens in slower ED version.
The shield is just a collider alongside the ship's colliders that deactivates when not in use, but it seems like I can't deactivate the collider like I was before and it's always on. I could perhaps instance it and free it but it also grows and shrinks by manipulating the circle shape's radius, this also no longer works at all, but did with default. Both versions do this.
If that collider is touching anything else it will get the RBody stuck. The ship will no longer gain directional thrust and just gets stuck on the object. the slower ED version is much better about this, doesn't seem to get stuck.
Collectables that once collected properly no longer do so and simply push the ship around if I manually override the shield off in the editor during runtime. So it seems like the layers are not working properly. This happens in faster version SIMD, the slower ED will collect when hitting the always on sheild
As it is I can't really use the addon to replace the default physics system at this time as I have no control over these issues and have no idea what is wrong or what to do.
Edit: Also, move_toward seems to automatically face in the direction in the faster SIMD one, objects that were not meant to rotate now do. Default does not. It also seems to turn toward using the bottom of the rigid body, as though down is forward. The default is right is forward facing. May be why the rotation of the ship doesn't follow the mouse as well. also updated to which versions these problems are in.
Overlapping spawns seem to need a lot more leeway or they create way more velocity on objects. Can just make sure overlaping objects dampen or spawn further away before applying any force. both versions.
https://github.com/appsinacup/godot-rapier-2d/actions/runs/8668226381/job/23772870624
After integration with salva2d, double builds fail. Needs to wait for salva2d repo to support double builds.
Salva issue: dimforge/salva#47
Compared to the actions of default, when set to the Rapier plugin, bullets travel much slower. Regardless of speed they also seem to not trigger the usual methods on collisions as the default does. Setting the speed much higher seems to fix this but doesn't match the default use. For example, look in the repo I sent @Ughuuu an invite to, should be set to Default and has Rapier (slow version) installed.
Edit: this and any other problems with speed can be fixed by:
if ProjectSettings.get_setting("physics/2d/physics_engine") == "Rapier2D":
and setting the values accordingly. Not sure what the magic number is but maybe something around [ speed *= 20 ] This may also affect other rigid bodies, like how fast the asteroids are when they spawn in, but it probably needs to match the speed of DEFAULT.
another edit: I will try to put a test scene in the res:// with easy bug reproductions so you can just test from there and not have to run the whole project to find the issues.
extends Node2D
var query: PhysicsShapeQueryParameters2D
func _ready():
# 1 by 1 square at origin
var shape: RID = PhysicsServer2D.rectangle_shape_create()
PhysicsServer2D.shape_set_data(shape, Vector2(0.5, 0.5))
var body: RID = PhysicsServer2D.body_create()
PhysicsServer2D.body_set_space(body, get_world_2d().get_space())
PhysicsServer2D.body_add_shape(body, shape)
PhysicsServer2D.body_set_state(body, PhysicsServer2D.BODY_STATE_TRANSFORM, Transform2D(0, Vector2(0, 0)))
PhysicsServer2D.body_set_mode(body, PhysicsServer2D.BODY_MODE_STATIC)
# circle query at 10, 10 with radius 100
var circle := CircleShape2D.new()
circle.radius = 100
query = PhysicsShapeQueryParameters2D.new()
query.shape = circle
query.transform = Transform2D(0, Vector2(10, 10))
func _physics_process(delta):
var direct_space_state := get_world_2d().direct_space_state
var results := direct_space_state.intersect_shape(query)
print(results.size())
Only prints 0
on Rapier2D, will print 1
on default
Using apply_impulse applies a lot of angular momentum to rigidbodies. Attached a small project that shows the behavior (click to apply impulse towards mouse)
Taken from fabriceci/godot-rapier2d#50
Describe the bug
On a RigidBody2D node with a circle collision shape and a physics material with bounce set to 1, the built in body_entered signal is not emitted on collisions with StaticBody2Ds.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
The body_entered signal should be emitted (Works properly on both Box2D and GodotPhysics)
Screenshots
If applicable, add screenshots to help explain your problem.
Environment (please complete the following information):
TODO
The credentials I put are out of date and signing fails.
Would be nice to have an easy way to have particles auto remove at the end of a specific time.
As of now, the addon has parts in c++ and a wrapper in rust.
Because of this, it's hard to make web builds work (because of the first wrapper in rust, it needs some js hacks to work).
GDext(godot-rust) extension somehow figured it out. It might be difficult to do here.
Also, cross platform determinism is way easier to do in rust than in c++.
That being said, I think it would be most beneficial to have all the code written in rust, and not have 2 layers of code(c++ and rust).
Describe the bug
Calling move_and_slide
when collision shape is disabled results in the following error
E 0:00:09:0544 ProjectileCollision.gd:61 @ _physics_process(): Condition "shape_count < 1" is true. Returning: false
<C++ Source> src\servers\rapier_body_utils_2d.cpp:46 @ RapierBodyUtils2D::body_motion_recover()
ProjectileCollision.gd:61 @ _physics_process()
Error location:
To Reproduce
Steps to reproduce the behavior:
move_and_slide
Expected behavior
Console shouldn't fill with error
Environment
Hi there! Great plugin. Recently came across this however found that this only works for Godot 4.x
Is there a way I can use this for Godot 3.x (specifically Godot 3.5)
Thank you
Describe the bug
One Way Collision doesn't work
To Reproduce
Steps to reproduce the behavior:
Expected behavior
The body should go through the one way platform.
Environment (please complete the following information):
The example project is: https://github.com/GeminiSquishGames/Rapier2Dbug
The box static collision has a physics material set for max bounce and friction, no absorb. The ball is a plain RBody. Switch between the two physics engines to see that Rapier behaves more erratically with the same settings as Godot's default which it should be set too when you open it. This is using Godot 4.2.1 mono,
Edit: Seems like rough-checked friction applies the wrong angular velocity, transfers to the opposite rotational velocity. Then it collects too much linear?
Describe the bug
There are two bugs:
To Reproduce
Expected behavior
As with default physics
Environment (please complete the following information):
Describe the bug
Rapier2D seems to crash if there is a collision shape 2D that is disabled in the Node inspector.
E 0:00:03:0538 _update_shape_transform: Condition "!rapier2d::is_handle_valid(shape.collider_handle)" is true.
<C++ Source> src/bodies/rapier_collision_object_2d.cpp:247 @ _update_shape_transform()
To Reproduce
Steps to reproduce the behavior:
Expected behavior
No error.
Screenshots
Environment (please complete the following information):
Example project(zip)
Please attach a zip with project where issue occurs.
Describe the bug
The segment between the first and last point on a CollisionPolygon2D with build_mode = BUILD_SEGMENTS
is missing.
To Reproduce
Steps to reproduce the behavior:
Environment
In the new versions rust rewrite, I use now a singleton locked with a mutex to access data.
Instead, I should give a reference to the data holder to all layers, and possiblity use a hashmap that can handle access from multiple threads(dashmap)
Objects that get attracted towards a point gravity area don't slow down once they moved across the gravity point.
To Reproduce
Expected behavior:
I would expect it to behave similar to the default godot physics engine. If a Ball is spawned close to the middle of the gravity point area it should move around the center point. But with rapier physics engine it gets thrown out.
I have tried playing with the physics parameters but i can't get it to work.
Environment :
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.