Convergence Posted November 21, 2015 Share Posted November 21, 2015 Since the default camera collision behavior is kind of awkward (camera 'glues' to any surface it bumps into until manually 'released'), I resorted to just try to prevent the camera from going underground, so to speak, with just moving its target upwards as much as the camera would otherwise be underground. http://www.babylonjs-playground.com/#1OWKH4 However the camera will start to flickr from going underground in one frame to being corrected in the next frame. More noticeable on lower FPS. How to prevent this? Thanks in advance Quote Link to comment Share on other sites More sharing options...
MarianG Posted November 21, 2015 Share Posted November 21, 2015 Like this ? Quote Link to comment Share on other sites More sharing options...
Convergence Posted November 21, 2015 Author Share Posted November 21, 2015 Like this ?Thanks, that would work if the ground is completely flat (yes, like the posted playground), but for the sake of this problem, assume a groundFromheightMap please, I just simplified the height calculation into a flattened map. Quote Link to comment Share on other sites More sharing options...
KarelAnker Posted November 21, 2015 Share Posted November 21, 2015 You could use a raycast each frame from the position of the camera of 1 frame ago to the position of the camera at the current frame. If something hits in that raycast, then you should set the camera position to the hit world position. Or have the raycast from the current camera position to the mesh you're looking at. Quote Link to comment Share on other sites More sharing options...
fenomas Posted November 21, 2015 Share Posted November 21, 2015 In my project, each frame I raycast from the camera target back to the camera, and zoom the camera in if an obstruction is met. But this is with a freely moving camera - doing the same thing with the ArcRotateCamera would take some trig, I guess. Convergence 1 Quote Link to comment Share on other sites More sharing options...
MarianG Posted November 21, 2015 Share Posted November 21, 2015 Oh, my bad. I tryed a long time ago something like. But I used ground.getHeightAtCoordinates, and this is not too fast. http://www.babylonjs-playground.com/#225AVVMaybe with raycast it's faster and more precisely. I'll try too Quote Link to comment Share on other sites More sharing options...
RaananW Posted November 21, 2015 Share Posted November 21, 2015 Since the default camera collision behavior is kind of awkward (camera 'glues' to any surface it bumps into until manually 'released')Just wondering - What do you mean by that? How would you expect the collision system to work? Quote Link to comment Share on other sites More sharing options...
Convergence Posted November 22, 2015 Author Share Posted November 22, 2015 You could use a raycast each frame from the position of the camera of 1 frame ago to the position of the camera at the current frame. If something hits in that raycast, then you should set the camera position to the hit world position. Or have the raycast from the current camera position to the mesh you're looking at.with an arcrotate camera the position cannot be modified directly, only alpha and beta I guess. In my project, each frame I raycast from the camera target back to the camera, and zoom the camera in if an obstruction is met. But this is with a freely moving camera - doing the same thing with the ArcRotateCamera would take some trig, I guess.I'll try this, thanks Though I'm not a big fan of Raycast for its speed. Oh, my bad. I tryed a long time ago something like. But I used ground.getHeightAtCoordinates, and this is not too fast. http://www.babylonjs-playground.com/#225AVVMaybe with raycast it's faster and more precisely. I'll try tooIt looks like ground.getHeightAtCoordinates uses a raycast as well, (and I believe that's why its slow). Just wondering - What do you mean by that? How would you expect the collision system to work?If an arcrotate camera collides with something, it stops (good), but when the cameraTarget starts to move while the camera is still 'glued' to its collision surface, the camera won't slide along with it. According to the docs: The ArcRotateCamera can also check collisions but instead of sliding along obstacles, this camera won't move when a collision appends. Quote Link to comment Share on other sites More sharing options...
fenomas Posted November 22, 2015 Share Posted November 22, 2015 I'll try this, thanks Though I'm not a big fan of Raycast for its speed. Well, in my case I'm doing it with voxels, so raycasts are very fast and there's no height map anyway. But even with a simple height map there can be a hill between the camera and the camera target, and if you want to catch those cases you'll need something - a raycast, or sampling the height map at multiple points, etc. In general I'd assume that using BJS's built-in raycast will be the slowest option, but it may still be fast enough to not bother worrying about. Convergence 1 Quote Link to comment Share on other sites More sharing options...
Convergence Posted November 22, 2015 Author Share Posted November 22, 2015 Well, in my case I'm doing it with voxels, so raycasts are very fast and there's no height map anyway. But even with a simple height map there can be a hill between the camera and the camera target, and if you want to catch those cases you'll need something - a raycast, or sampling the height map at multiple points, etc. In general I'd assume that using BJS's built-in raycast will be the slowest option, but it may still be fast enough to not bother worrying about.Since its only one pick per frame, its acceptable, though it looks like the single pickWIthRay call already makes it in the top 5 most time consuming function calls in the profiler.. my solution using the pickWithRay method and ArcRotateCam :if (obstruction = scene.pickWithRay(cameraRay, function(mesh) { return mesh.checkCollisions; })) { if (obstruction.hit) { camera.radius = BABYLON.Vector3.Distance(obstruction.pickedPoint, cameraTarget.position); }} Quote Link to comment Share on other sites More sharing options...
fenomas Posted November 22, 2015 Share Posted November 22, 2015 Yep, that's basically what I do, plus I add in a small offset to avoid partly seeing through the ground when the camera's near plane intersects it. I tried a couple of ways of doing this and it got pretty hairy; I think what I settled on is: whenever the raycast hits an obstruction, I shift the camera by a small amount (0.05 or something) along the normal of the raycast collision. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.