Rays and Spatials

Ok I’m really stuck with this problems. Im searching now for days and dont get clear answers.
I followed the tutorial how to shoot a ray and collect the intersections and stuff.
With .getName() you can easily access the name of that Geometry.
Twist:
assetManager.loadModel(“blaa”);
returns a spatial!

So how am I supposed to shoot a ray and get information from that spatial?!
I mean .getName() does not work anymore because its a spatial.

I want to implement destroyable objects. So i can say something like.
.getLifes() < 1 -> destroyed.
I dont want to apply that onto a geometry with .setUserData() because I also want to add a custom mesh and model.
Im so confused right now…
I dont know how I should fix this.
Please help me!

  • Daniel

“I expect a labrador but I only get a dog”
https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:scenegraph_for_dummies

I watched that tutorial so many times.
This is a real issue man. I found that problem many times around the internet and know one has a proper answer. It wont help me to watch that scene Graph thing again!

I cant make this with my own magic… I dont even believe that I was ever able to.
I just need an idea how to do this!

So you have to watch the tutorial again, man, you seemingly didn’t understand it. A Spatial is either a Geometry or a Node, as the tutorial clearly states. You just cast it to the right sub class.

Geometry geom = (Geometry) spatial;
or
Node node = (Node) spatial;

Its even written clearly in the other thread you answered in. If inheritance and casting is “magic” to you then you should really, really up your Java skills before continuing trying to make a game. Or move to something like RPG maker or so.

Guess what buddy,
I tried to cast it and it says node is not castable to geometry.
The point is that my spatial is declared as a spatial in the constructor. Why would it change to node? And if I try to cast it back to spatial and fails because it already i a special.
Mind = blown.

So please dont tell me things like go to RPG maker. Dude im trying to learn something and I try hard but there is a point I need help from pros like you. Dont judge me because I fail at some point.
I understand all basics around that topic (because I spent days googling everything)
But as you may know: learning things by hard or just reading is not very effective. You need to mess around with what you learn so you’ll keep it mind. So please dont be like many people on the internet and give me a fair chance to learn from your words. Thank you :slight_smile:

@Pixell said: Guess what buddy, I tried to cast it and it says node is not castable to geometry. The point is that my spatial is declared as a spatial in the constructor. Why would it change to node? And if I try to cast it back to spatial and fails because it already i a special. Mind = blown.

Again, what you say is basically:

“She said she had a dog but when I came there I found out it was a labrador, wtf? When somebody says ‘dog’ I expect a german shepherd dog.”

See the issue? If you still don’t, try reading the beginning part of scenegraph for dummies again, please.

@Pixell said: So please dont tell me things like go to RPG maker. Dude im trying to learn something and I try hard but there is a point I need help from pros like you. Dont judge me because I fail at some point. I understand all basics around that topic (because I spent days googling everything) But as you may know: learning things by hard or just reading is not very effective. You need to mess around with what you learn so you'll keep it mind. So please dont be like many people on the internet and give me a fair chance to learn from your words. Thank you :)

I don’t judge you, I tell you that your choices are either learning Java or going to some tool that doesn’t require you to learn Java to achieve what you want to do. Casting and inheritance are really basics and if you fail here you will fail even harder the more complicated your game becomes. As for helping you understand the basics, I really don’t know how to explain it any better than I do in the scenegraph for dummies tutorial I spent days on making. Maybe the dog analogy works, idk.

Haha :smiley:
Well thanks for your suggestion. I take this as a advice and I’ll try me best.
But maybe you want to have a quick look at this:

[video]2D Java game from scratch - Alpha - YouTube

I speak java, maybe my accent isnt that good :wink: