Note that there are some explanatory texts on larger screens.

plurals
  1. POcollision detection doesn't push back
    primarykey
    data
    text
    <p>Alright, so I'm working on collision detection for a 3d game, this is what I got so far:</p> <pre><code>public void mapCol(Spatial map, Node model2){ Mesh m = (Mesh) ((Node) map).getChild("obj_mesh0"); int c = 0; m.updateWorldBound(true); boolean col = false; c = m.getMeshData().getPrimitiveCount(0); // System.out.println(c); Vector3[][] v3 = new Vector3[c][3]; for(int s = 0; s &lt; c; s++){ v3[s] = null; v3[s] = m.getMeshData().getPrimitive(s, 0, v3[s]); Vector3 min = new Vector3((float)Math.min((float) Math.min(v3[s][0].getXf(), v3[s][1].getXf()), v3[s][2].getXf()), (float)Math.min((float)Math.min(v3[s][0].getYf(), v3[s][1].getYf()), v3[s][2].getYf()), (float)Math.min((float)Math.min(v3[s][0].getZf(), v3[s][1].getZf()), v3[s][2].getZf())); Vector3 max = new Vector3((float) Math.max((float)Math.max(v3[s][0].getXf(), v3[s][1].getXf()), v3[s][2].getXf()), (float)Math.max((float)Math.max(v3[s][0].getYf(), v3[s][1].getYf()), v3[s][2].getYf()), (float)Math.max((float)Math.max(v3[s][0].getZf(), v3[s][1].getZf()), v3[s][2].getZf())); Vector3 v2 = new Vector3(); v2 = max.add(min, v2); v2.divideLocal(2); if(max.getXf() &gt; model2.getTranslation().getXf() - sp1.getRadius()&amp;&amp; min.getXf() &lt; model2.getTranslation().getXf() + sp1.getRadius() &amp;&amp; max.getZf() &gt; model2.getTranslation().getZf() - sp1.getRadius() &amp;&amp; min.getZf() &lt; model2.getTranslation().getZf() + sp1.getRadius() &amp;&amp; max.getYf() &gt; model2.getTranslation().getYf() + sp1.getRadius()&amp;&amp; !col){ float cosine = (float) v2.dot(v2); float angle = (float) Math.toDegrees(Math.acos( cosine )); float pangle = (float) Math.toDegrees(Math.atan2((min.getX() + ((max.getX() - min.getX())/2)) - model2.getTranslation().getX(), (min.getZ() + ((max.getZ() - min.getZ())/2) - model2.getTranslation().getZ()))); if(min.getY() &lt; max.getY()){ System.out.println("pangle:" + pangle + " angle:" + angle); model2.setTranslation( (min.getX() + ((max.getX() - min.getX())/2)) - (Math.sin(Math.toRadians(pangle)) * (sp1.getRadius())), model2.getTranslation().getYf(), (min.getZ() + ((max.getZ() - min.getZ())/2)) - (-Math.cos(Math.toRadians(pangle)) * (sp1.getRadius())) ); col = true; } } } } </code></pre> <p>Now the part to really look at is right here:</p> <pre><code>model2.setTranslation( (min.getX() + ((max.getX() - min.getX())/2)) - (Math.sin(Math.toRadians(pangle)) * (sp1.getRadius())), model2.getTranslation().getYf(), (min.getZ() + ((max.getZ() - min.getZ())/2)) - (-Math.cos(Math.toRadians(pangle)) * (sp1.getRadius())) ); </code></pre> <p>Any idea why it wouldn't set model2 modle2's radius away from the wall? (making it stop at the way and able to go no further)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload