-
Notifications
You must be signed in to change notification settings - Fork 863
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New physics behavior #775
New physics behavior #775
Conversation
Incredible 😍 |
* Compare joints objects * Get joints anchor points * Read/Modify distance, revolute and prismatic joints settings
* Read/modify pulley, gear, mouse, wheel, weld, rope, friction and motor joints
Loving this, but you made a copypasta error I think 😄 In physikruntimebehaviour.js The Wheel Joint Definition.... Line 1686
and line 1711
Both should be maxMotorTorque Apart from that I got the Wheels working fine 👍 |
That's really cool! We should definitely have both the demo that you made as example! :) |
Fixed!, thanks, surely I've a lot of these, there are tons of settings :D |
One other thing, It took a few seconds for me to find the Mass setting.... It is labelled Density, which is fine if you know this stuff but for beginners I think either Mass (Density) or vice versa, or just Mass 🤔 |
I guess mass is computed by multiplying the density and the surface of the object. Might be useful to put something like |
Ok, I'm used to setting mass explicitly, but I like the way box2d does it 😁. This is going to be super powerful 😊 |
The old setting was used as the density too I think, this way is more clear, because set mass = 2 is not the same that set density = 2. I've tried to port Box2D as is, but I've made some modifications for easiness (global position for joint anchors and forces applying point). So... If you people think it's better to put the mass, I can use that mass and calculate the shape area to get the density in the background :) |
No, it's good, we'll make it clear in the doc 😁 |
And improve response on object size modifications
Ok, it should be almost free of bugs, tested every setting, just missed some default values on joint creation And here are the test files |
Looking very good 😊. Just 1 question right now, how are you supposed to use the edge shape, and when might we get polygons? 😋 |
The edge shape is almost the same than a box, but it's mean to be static and is a bit faster, so it's better suited for level grounds. Polygons could be already added, I did some code in a custom test file, so I know it works and can already put the working code in GD... But to be useful we need a polygon editor. |
Can't you get the polygon data from the sprite polygon data. We can already edit that, although it's a little clumsy interface as added dots all go to 0,0 right now. I should probably have said points or vertices 🤣 |
Although it's the most common use case, the object to which you attach the behavior is not always a sprite. |
So for now the editor for behaviors (
Finally, the question is: where to write this new editor/dialog? For now, the answer is: directly inside newIDE. Ideally the extension would be able to bring their own editors as part of the extension source code. But this is difficult because the "compilation" of newIDE is done only for files in You can see that for example, for now, all objects editors are in So the answer would be: we need to create a |
Yes, it would be dirty. Ideally behaviors should 100% stay separated from the underlying object having them. We could provide way in the IDE to copy the collisions mask to physics polygon, but that's more a convenient option than what should be the default :/ |
What I can do right now is enable a new string label in the behavior, here the user can enter the points in a list (as in the old IDE, but in pixels, no meters). Then try to parse it in the code. |
@4ian Will start doing the polygon, merge it when you want, if I don't add the polygon now will do it for the editor, I'll rewrite the wiki page too! |
@zatsme That's a very true concern! I think I'll work on something to warn about potential conflicting uses. Maybe gray out a behavior if another one is already used in the game (i.e: if Physics is used, gray out Physics2 and vice versa - including actions/conditions/expressions). If you still try to use them, you'll get a warning "You're trying to use XXX, but the game is already using YYY. Are you sure you want to use both? This could result in unexpected/conflicting behaviors of objects on the scene". This could be extended to the use of forces with objects having a behavior like Physics/Physics2. More generally, there are a few things that I'd like to warn users against (making weird hitboxes with platformer engine, using sprite of different sizes in platformer engine, launching music in a loop, and using image that are too large). All of these are not related, but could be really useful. |
Very handy! |
Yes, as much as I'd like to merge this now and have the new behavior and demo integrated, we should be a bit cautious - especially because GDevelop was criticized in the past for being confusing on multiple parts... It's also on us to make sure that things are easy to use properly, and hard to use improperly :) And if we can avoid/reduce drastically the number of users asking the questions on the forum/discord, that's great :) |
Would it be an idea to have an extension/behaviour type Id? Then when a behaviour/extension is used for the first time the ide can Check if another of the same type is already used and warn. If physics was Id Phy1 and physics 2 was Phy2 then you can warn that a type of Phy was already in use and it's also a later/newer version. That way if we ever get to a point where GD5 is being extended by many devs like construct and game maker then the parser can warn against issues automatically as long as the extension type is present. 🤔 |
Yes, that's what the internal name of the extensions are for :) What could be done here is a quick helper in newIDE codebase that gives the extension used by a game (it's already done in This could be refined to events to detect usage of incompatibles actions/conditons on some objects (we should have all the tool needed to list the actions/conditions used on a specific object). |
For warning users about forces on object that have the physics behavior, that is surely a bit simpler that what I describe: In the selector of instructions (internally, the word "instruction" represents a condition or an action), if the user choose a condition or action for an object, check the behavior of this object, and send it to the class/helper for incompatibilities. I've added a task for it here: https://trello.com/c/xq91to0I/218-warn-the-user-against-using-incompatible-actions-conditions-like-using-force-on-an-object-that-have-the-physics-behavior Here is the roadmap with all the "productivity" warnings that we could add: https://trello.com/b/qf0lM7k8/gdevelop-roadmap?menu=filter&filter=label:Productivity%20friendly%2Favoid%20common%20errors If you have other ideas, let me know and I can add them here :) |
Should the polygon origin be at the center or top-left of the object? |
What are the impacts/implications of both solutions? |
No idea, thinking about it... On object size change (and if shape scale is not changed), if the origin is at center it will stay centered (small offset in all the directions), but if the origin is at top-left all the shape offset will be at the bottom-right. |
Can't we define it as we do with sprites? |
A choice Polygon Origin: TopLeft/Center ?, could be, don't know. |
If we can, we should make this choice for the user no?
I guess the way polygons are defined in Box2D is a bit different than hitboxes (there can be a single polygon for example). Also, polygon can't/should not change for every frame - this would be a nightmare in terms of performance. I'm almost thinking of adding a big warning against making different hitboxes for every frame btw. |
I'm checking out GD4 (oof haha), and the polygon editor indeed let the user choose object center and origin (and for some reason top-left option is commented out in the sources)
For sure, what I'm doing right now is storing the vertices in a memory buffer, they aren't recomputed on shape size change, but you've to pass them to the body again in a new shape, so every contact has to be recomputed. |
Good and bad news, good ones: I get it to work, and have proofs :) The bad ones, @4ian , do you have any idea why the parser converts an empty array into a JSON empty object, and non-empty arrays break the parser, skipping next properties? |
@4ian Merge it if you want, the conversation is getting long and it seems it will take ma a while to get what's going on, for a feature that won't be available anyway :) |
So the serializer in C++ is not properly handling these arrays it seems. I can help to take a look at it. This way you can continue working on the polygons on another PR :) |
In short it's because the Serializer was originally created to be compatible with XML and JSON. XML does not have arrays but multiple children with the same name. I think we should be able to have a "isArray" boolean stored in the SerializerElement when reading the JSON. Then when writing back the SerializerElement, it would be properly outputted as an array. I'll take a look! |
@Lizard-13 Fix was actually quite simple. Made the fix in 238b6a2 and added tests for this. I've updated libGD.js, remove it from public/libGD.js and relaunch Let me know if you still have an issue! |
Merge changes from GDevelop master into the branch
I'm a bit lost with this one, I've cherry picked your commits into my ligGD.js, but still failing to read the array. the SerializerElement passed here: |
If you have merged master into your branch, there is no need to cherry pick anything right? |
Hey, you're right, but I did it before merging master, not sure why 😅 |
Let's merge this now! I'll hide the extension for the next version and add a preference to display it once we have help and a way to make sure users can't misuse the two behaviors ;) |
Huge huge thanks for your totally awesome work on this. 💯🎉 This is a huuuge feature! I have no doubt that lots of game will use it soon - and the demos are super impressive. 😎 It's a great example of GDevelop being able to handle complex games with advanced physics! 🚀 |
Does the polygon physics work now on GD5? Can show me some example? |
Please ask this on the forum or on the Discord :) |
Also simplified the world scaling, no more negative values and opposite angles here and there :)
EDIT: Forget to say that almost every position and angle value in joints settings are in world coordinates, so you can add joints using sprites points for example, without worrying about the object rotation.