I’m currently dealing with the third-person controller indoors. How can I protect my camera from invading walls? Such as the Cinemachine Colider Script.
by user 684154017479524352
I’m currently dealing with the third-person controller indoors. How can I protect my camera from invading walls? Such as the Cinemachine Colider Script.
by user 684154017479524352
You could make raycasts and get a safe position.
https://engine.needle.tools/docs/getting-started/for-unity-developers.html#raycasting
Check the distance between the ORIGIN and the CAMERA POS and the distance between the ORIGIN and the SAFE_POS.
If the SafeDistance is smaller then the CamDistance, that means the camera is “in the wall” and we want to correct it, if opposite we do not want to edit the camera at all.
Variant A: set the position of the object directly and hopefully OrbControls will just pick up where you left them off. It is updated with onBeforeRender
, so your corrections will be in update
.
Variant B: you’ll have to blindly call the DollyIn and DollyOut functions. So suppling the expected distance on where you want to be.
The OrbitControls are bit hectic as of right now, since there are A LOT of requirements for a camera system and it is unrealistic for one system to fit them all. In the future there will be most probably separate camera scripts with simple and polished usecases. But the goal here is not to support every usecase.
If anything wasn’t clear don’t be afraid to ask
Ok, THX.
by user 684154017479524352
@matmat you can also use camera-controls for the camera, which contains a collision avoidance sample:
https://yomotsu.github.io/camera-controls/examples/collision.html
Good idea, I’ll try it. Thanks.
by user 684154017479524352
Perhaps this code snippet is useful for getting started integrating the package: needle-engine-samples/package/Runtime/CameraControls/camera-controls~/CameraControlsSample.ts at 8d61269af8f17638c3136cdf2b342a4bafb8795e · needle-tools/needle-engine-samples · GitHub