![godot rigidbody2d godot rigidbody2d](https://i.ytimg.com/vi/upcat4Nsz50/maxresdefault.jpg)
I'll mention any case when you need to write code somewhere else. If I say Class( 2D), I mean that what I'm saying applies for both Class and Class2D.Īlso, since we are talking about physics, in general you will be working in _physics_process. On that note, just in case, know that 3D objects can't collide with 2D objects. While the question is about 2D, for 3D it is mostly the same provided you use the 3D versions of the nodes. No, you don't need to know all that, but you asked for "everything very thoughrouly". And I'll mention some stuff about raycast and area, and other queries at the end. Then filtering physic bodies and communication.
#Godot rigidbody2d how to
Where & how to connect and write the codeįor this answer I will start by explaining collision layers and mask. Where and how do I add a collision shape 2d or area2d or other nodes along those lines. some examples of things I would like to be more clear are Please explain everything very thoughrouly as I have been trying for the past couple of days to figure it out but most of the places I have looked I didn't understand what to do and when I copied the code it didn't work. I want to detect when the mob touches the player and give an output finally I have the main scene with has the player scene inside it and instances the mob scene every so often to spawn mobs at the top of the screen. this scene only has the sprite and a tiny piece of code that makes it so that the mob deletes itself once it leaves the screen using the visibility notifier(I also turned of the mask square so there would be no physic). I also have a scene named "mob.tscn" which is a rigidbody2d node. this scene is a player which moves from left to right across the screen. one that is named "KinematicBody2D.tscn" which a KinematicBody2D node. Making this change would be considered breaking, but as long as it's documented I think 4.0 is the perfect time to make such a change.I have 3 scenes.
![godot rigidbody2d godot rigidbody2d](http://www.daydev.com/wp-content/uploads/2018/01/Screen-Shot-2018-01-04-at-2.21.04-PM.png)
This is how other physics engines like Box2D handle this, and how Godot's 3D physics handles this, so I believe the issue is Godot's 2D physics not clearing applied_force after each integration.
![godot rigidbody2d godot rigidbody2d](https://i.ytimg.com/vi/7JCRpY3biZg/maxresdefault.jpg)
The current implementation, however, does not do this, as calling add_force each physics step will cause the rigidbody's velocity to increase exponentially. In the documentation it's explicitly stated that apply_impulse should not be used each frame to apply a continuous force, since its change is immediate and framerate dependent, where applied_force is modified by the step delta during integration.Īnother way to look at it is that add_force should be used each physics step where it is affected by the physics delta in much the same way as moving a Node2D over time by multiplying a velocity vector by delta time. The purpose of apply_impulse is to cause an immediate, large change to the velocity, where add_force applies a continuous change over time by being called during each _physics_process(). The issue I see is that in the 2D physics applied_force is added in its entirety during the integration step, but is never reduced or cleared, so it will continue to accumulate indefinitely. Your minimal reproduction project doesn't show the difference between 2D and 3D because the 3D project uses add_central_force() and the 2D project uses apply_central_impulse() so the different behaviour is to be expected. In the phrase "constant directional force" I take constant to mean that the magnitude of the force is constant, not that it will be applied persistently.įwiw analogous calls in other frameworks don't exhibit this behavior by default, so it feels like a reasonable assumption it wouldn't here too, especially since it doesn't in 3D RigidBodies. In both 2D and 3D, the damping values only seem to decrease velocity over time ( 3D, 2D), not applied_force, unless again I'm missing something? The equivalent line of code is not there for 2D, unless I'm missing something. In 3D the applied_force is cleared at the end of integration. Instead linear_damp and angular_damp are used to slowly decrease these values over time. From the documentation: They are used to add a "constant directional force (i.e. Add_force(), add_central_force() and add_torque() are accumulative and are not cleared both in 2D and 3D.