Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to stop camera from moving through walls?
    primarykey
    data
    text
    <p>I'm making a game using <a href="http://github.com/danielrh/jiglibjs" rel="nofollow noreferrer">JigLib</a> and <a href="http://www.glge.org/" rel="nofollow noreferrer">GLGE</a>. The camera follows the player the way I want it to, but when the player is close to a wall, the camera moves to the other side of the wall, which is annoying when there is something that needs quick reflexes.</p> <p>I tried using picking to move the camera when it can't see the player, but it only moves until half of the wall is in front of it and half is behind it, making an annoying split screen effect where one half of the screen is blank.</p> <pre><code>camera.setLocY(Math.max(playerMesh.getLocY() - 10, 3)); camera.setRotY(playerHeading); camera.setLocX(playerMesh.getLocX() + Math.sin(playerHeading) * Math.max(camera.getLocY() - playerMesh.getLocY() + 5, 0)); camera.setLocZ(playerMesh.getLocZ() + Math.cos(playerHeading) * Math.max(camera.getLocY() - playerMesh.getLocY() + 5, 0)); camera.setRotX(Math.atan2(playerMesh.getLocY() - camera.getLocY(), Math.max(camera.getLocY() - playerMesh.getLocY() + 5, 0))); var playerVec = [playerMesh.getLocX(), playerMesh.getLocY(), playerMesh.getLocZ()], cameraVec = [camera.getLocX(), camera.getLocY(), camera.getLocZ()]; scene.removeChild(playerMesh); scene.removeChild(floor); do { var ray = scene.pick(canvas.width / 2, canvas.height / 2); if (ray.distance &amp;&amp; ray.distance &lt; GLGE.distanceVec3(playerVec, cameraVec)) { camera.setLocX(ray.coord[0]); camera.setLocY(ray.coord[1]); camera.setLocZ(ray.coord[2]); cameraVec = ray.coord; camera.setRotX(Math.atan2(playerMesh.getLocY() - camera.getLocY(), Math.max(camera.getLocY() - playerMesh.getLocY(), 0))); } } while (ray.distance &amp;&amp; ray.distance &lt; GLGE.distanceVec3(playerVec, cameraVec)); scene.addChild(playerMesh); scene.addChild(floor); </code></pre> <p>Is there a resource where I could find information about how to move the camera to avoid walls? Is my code wrong?</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.
    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