Hello everyone,
Im trying to get mouse-click point on my terrain.
I loaded terrain as plane-mesh.egg and set from a heightmap with a shader;
But I’m getting incorrect coordinates depending on the camera angle.
Here code;
Wait, are you saying that you’re using a shader to deform a flat mesh via a height-map?
Because if so, the collision-system won’t I daresay have access to the deformed state of the mesh–only the original, un-deformed state.
As a result, the issue may be that the ray is detecting positions on the underlying flat mesh, which naturally doesn’t match the height-mapped visuals.
Yes i did like you said. Before i tried ShaderTerrainMesh but i couldn’t use collision with it. Then i decide to do this.
Another option is using GeoMipTerrain, do you know is that have collisions? Or maybe i can use another plane to get collision without rendering?
GeoMipTerrain… may allow this sort of visible-geometry collision? I’m not sure, to be honest.
I would like to give a note of warning that colliding with visible geometry as you currently are may become a performance issue as your scenes become more complex.
Returning to the main topic, let me say: it’s probably not impossible to get a collision-point with your shader-based terrain–but it’s not something that I’ve looked at much myself, I fear, so I don’t know what method to recommend.
(Off the top of my head, one idea is that you might be able to access the depth-buffer, then use that with the mouse-position to determine the point in 3D space that is being indicated.
But I stand to be corrected by others if there are better approaches!)
Hmm… This is perhaps a long shot, but in your flattened version, your shader doesn’t still have some sort of vertical offset, does it…?
Because in that version it really does look like the picker is simply off in the vertical–note that it seems to be accurate when looking directly downwards…
I’m really not sure of what’s going wrong in your code, at least without examining more of it.
Pretty much the same way, I daresay!
What you’re doing is pretty much correct I believe (save for the whole “colliding with visible geometry” thing, arguably)–which is why it’s so odd to me that it’s not working!
On another note, by the way, something that I noticed in your code:
This should, I believe, never be true: the list should never have fewer than zero items in it.
There is a new experimental CollisionHeightfield solid in the master branch of Panda3D, if you are comfortable building from source and/or using a development build.
Omg same with GeoMipTerrain too
I tried;
-LoadModel(plane.egg) with vertex/frag shaders - same
-LoadModel(plane.egg) withot any shader - same
-ShaderTerrainMesh - i think the best option i ever tried for a terrain but CollisionRays did not detect this idk why?
-GeoMipTerrain - same
i cant even doing this basic things for the game
There is a new experimental CollisionHeightfield solid in the master branch of Panda3D, if you are comfortable building from source and/or using a development build.
ShaderTerrainMesh is deformed on the GPU, so it doesn’t have a CPU-based mesh that you can meaningfully test against collisions with.
So, if we use ShaderTerrainMesh, we cant use any collision events? (like getting mouse click pos)
Is there no way for this?
Is this a coordinate space issue? Does your player have a parent that has a position relative to render?
Yes, I think there is something wrong with camera or ray vector im not sure . Or like you said im not sure again. Its getting wrong coordinates depends camera angle;
Plain.egg test with shaders (using heightmap in vertex shader);
Plaing.egg test without using heightmap;
Also i tried wiıthout any shader and other terrain options.
Here my actor codes;
As I said, I daresay that it can be done–such as via accessing the depth-buffer–but it’s not as simple as colliding with visible geometry.
I think that rdb is suggesting that the problem might be to do with the setup of your character, not of the ray.
All right, let me ask this: if you use the out-of-the-box “smiley” model, or even “Ralph”, does that affect the results that you’re seeing at all? (When using an untransformed, flat landscape, of course.)