Hello!
I’m pretty new to jMonkey(coming from pure Java) and have some questions that I cannot find anywhere. I have created a terrain using terra-monkey (the terrain you create in the SDK) and then added models into the scene using scenecomposer. I have then added a player and jbullet coliders so I can walk around in the world. But is there anyway to get the stuff from the scene. e.g I added a dinosaur and want my player to die if he walks into me. Or I have created a light in the scene but can I modify it dynamically?
Cheers!
Simon
You can add user data (spatial.setUserData() ) to any spatial. There you can set it like this: spatial.setUserData(“mobType”, tRex");
Then when you collide with it, check the user data of that object and keep checking its parent, and its parent’s parent, checking the user data for each until you find what one has it (since there will be child nodes and geometries below where you might have set that “mobType” user data.
If you cast something to (Node) you can then access the children using getChild…you can also do a lot by adding controls to the objects. For example attaching a “carnivore” control to the t-rex might make it wander around eating things.
…however that’s a pretty fragile way to build things. Generally mobile stuff like the t-rex you would be better off adding programatically - then you have full control of it from your code.
Ok, but if I make everything by code then it makes alot harder to see if models are perfectly at the right position. right?
Fixed objects, use the scene composer that’s what it is for.
Moving objects by definition are moving though…so perfectly the right position is wherever their movement code says they should be…
So for everything that is dynamically I use the init and update loop?
So for everything that is dynamically I use the init and update loop?
Read up on controls and application states as they allow a way to manage your init and update loops…but yes.
I will, thanks!