How would i go about making a custom implementation of a physics engine. the reason why i wanna do this is because i wanna build a 2D game and i wanna use JBox2D as my physics solution rather than bullet. how would you guys recommend me doing this? or would it even be possible to do this with JBox2D?
I donāt know how jbox2D works, but thatās usually a matter of āreplicatingā your scenegraph into the āphysics spaceā of the physics engine, and to mirror the transforms from the physics space to the scene graph.
For that, you can make a physics control that you attach on each spatial and that sets the position of the spatial.
You could also have a more broad solution, with an AppState that updates the position of physics influenced spatials.
Though, several people on this forum use a 2D physics engine called Dyn4j, that has been successfully integrated with JME.
Yeah, dyn4j is a nice one.
Basically, you have to stop thinking of your JME spatials like game objects. They are just the visual representation of your game objects. Just like your physics objects will be the physical representation.
So once a frame you just have to make sure the visuals match the game state.
In this respect the beginners guide is a little missleading. With all that control and user data and savable stuff you think, that this is the perfect game object. At least that happen to me and I first had hack myself in a corner a couple of times until I started to get that advice serious.
And that alone was not enough I also had problems to make an archtecture where that separation takes place.
Thatās why I started those blog articles to show one way out of this problem.
My reply is a bit off topic ⦠but this answer is awesome, and itās exactly what we need to say to people that create a network game. So plain and simple, so clear: spatials are NOT game objects.
Wow.
And for the topic: just like other said: every frame pick the informations about the object (rotation, position ⦠remember that they will likely be in world coordinates and if itās so youāll have to translate them in local coordinates, this can be trivial if every spatial are direct child of the world node (likely the rootNode, but maybe you could use the guiNode as itās alreay ortho etc) but if it isnāt the case you can have a look at how this is done for jbullet (i think i can retrieve the code if you donāt find it).
Tips ? Be sure that you can display a 2D object somewhere, move it āby handā to be sure that you can move it, pick a trivial-from-a-tutorial example that works with jbox2D, try to bind the position of the graphic object with the position of the object in the physic simulation. You can also display the position you got from the physic engine with a plain old System.out.println.
Off topic as well: That counts for every game.
Off topic too⦠that counts for every single application you are going to make in a dev careerā¦
MVC is a very very common dev pattern, and maybe our mistake is that we just take it for granted that users will use it. And youāre right that the examples are not exemplary in this regard.
What makes a simple example does not always make for a good design in a real application.
@nehon: Yes that counts for every software. Most often your āengineā or architecture leads you to the right direction. At least that is the case in my real life.
I would more say that the features of spatial can be misleading not the examples itself. In the examples you use those features which just cement the way toward the wrong direction. But those features as well can be very use full wisely used. So in the end the guy in front of the computer is to blame, like usual
So maybe I should correct it and say: ā⦠could be misleadingā¦ā instead ā⦠is a little misleading ā¦ā
Just that I said it, the beginners section is one of my favorite place in the wiki, those hello samples was the āthingā which told me āthis is the game engine I want to useā! So keep the good work up everybody.
I think that the most misleading this is:
1 - controls on spatials. What are they ? (i know how to use them, how to implement them etc, that is not my question). Especially, what are they if a spatial is only the visual representation of you game objects.
2 - userdata stuff. They are quite yummy, of course, but they give the idea that you can put datas there (like hp etc).
maybe in a jme 4 or later we could try to give an implementation to the model (the model of āmvcā) but it sounds a bit like āmaybe we can try to give an implementation to all-and-everything-possibleā.
I donāt know how ut engine (or unity, or cryengine) handle this question.
It would also be a nice cement to implement a generic server.
But the question here is more about philosophy than about coding.
JME is nice because it doesnāt force you down a particular path⦠which is why some of us can successfully use an ES and other donāt have to.
I am not talking about forcing anyone to anything. I donāt like nifty, i donāt use it. But i was happy to found it when i started jme.
I use the bulletengine but i can remove it easily. I love this.
Create something that both help people structuring their code and allow them to have a network based game in one click, will not oblige them to use it.
(and about es, as i donāt know where to ask the question: am i right if i say that the oop approach fails with the problem of the nominalism
BIG PARENTHESIS START
( Nominalism - Wikipedia ) i.e. we want to say that a horse has 4 legs, a tail, X teeths etc, but what happen if a horse has only three legs ? we say that itās a hors with three legs but itās like a nonsense. And when we define the inheritence in our classes we create such category, like a horse, and we want to perform actions on any element of the equivalence class, like āwalkā. Problem, if a horse is crippled it canāt walk. We could say that itās not āhorsesā that walk but āhorses with 4 legsā (so we remove the āa horse has 4 legs ruleā from the horse definition) but then the question is: āwhat is a legā. And the problem goes on and on, until we reach the level of atomos (literally: something we canāt cut) where we can define some properties without the risk of being wrong. Problem: at this point we could as well delete the horse requirement for the walk actions, as we are actually describing without any āmeaningā what can walk (we can also remove the ālegā thing, we explained the semantic so much that we now have only syntax)
BIG PARENTHESIS END
and the es system, instead of saying what objects are says what objects have (and a horse can has the ability to walk but he can also donāt have it).
I was thinking about that (philosophy about es) for days, but i didnāt wanted to create a topic only to talk philosophy, itās like not related at all with jme.
Btw, are you the inventor of the entity system principle ?
Thatās sort of it. ES is data-oriented and OOP tends to be method/encapsulation oriented.
Nope. I wish.
I created Zay-ES which is a āpureā ES implementation (as opposed to some less pure Java ES implementations). But I basically learned about it like a lot of others⦠from articles on the web that someone pointed me to (thanks @normen). I went from skeptic to rewriting my whole engine in about a month. After a while, I refactored Mythruna to pull the ES out into its own library.
Now every game I start or make is always ES-based.
It is not incompatible with OOP. The OOP allow very good implementation of this architecure, but it is not a perfect fit in matter of performance (who cares?)
Entity system has been used for the first time in the game Thief: the dark project in 1998, as far as I know.
I would say the current form of ES systems is not that old actually,
http://mud-dev.zer7.com/2007/11/33713/
before they were not that pure implementations, aka systems seperation of logic, entity is only id.
Thatās a great reference, by the way. Thanks for the link.
Itās nice to see some things distilled that I had to piece together over several t-machine articles originally.
Edit: or maybe itās exactly what I read originally and I just have lots of concrete examples to draw from this time⦠as thinking about it, thatās what this article really misses.
Edit2: yep, exact same articles I started with. Itās the examples in part 4 or 5 or whatever the drove it home. Sad that the originals are gone now, I guess.
Thanks for all the replyās! im liking the idea of dyn4j thanks guys
Iāve just integrated Dyn4j to Zay-ES in the sample project of Alchemist, and itās perfect
I can provide the code if you wish to have a look.
Not to hijack this thread, but I guess you got your stuttering problem worked out?
After some debug I confirmed it was not in the game logic but in the multithreading, as you pointed out. Iām running the culprit logic into the rendering thread for the moment. I will implement your solution the day it becomes an issue.