Timeline for How do I position a mesh just outside the camera view?
Current License: CC BY-SA 4.0
29 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Aug 23, 2019 at 14:13 | history | edited | Chillersanim | CC BY-SA 4.0 | Added note about the resulting distance not being exact... |
| Aug 23, 2019 at 14:12 | vote | accept | tmighty | ||
| Aug 23, 2019 at 13:52 | comment | added | tmighty | Let us continue this discussion in chat. | |
| Aug 23, 2019 at 13:50 | comment | added | Chillersanim | I'm not going to provide all your code. I provide a solution to the original question: "How to calculate the objects position". The solution is flexible enough to allow for any distance. I only used a fixed distance in the usage example. If you want to continue this chat, I would suggest we move it to a chat room. | |
| Aug 23, 2019 at 13:48 | comment | added | tmighty | And please don't use a fixed distance! Can you use my approach? -> float fDist = Mathf.Abs(Camera.main.transform.position.z - this.transform.position.z); I have the script on the Cube, so it should be fine. | |
| Aug 23, 2019 at 13:48 | comment | added | tmighty | For me, it does affect the results. Could you have a look? | |
| Aug 23, 2019 at 13:47 | comment | added | Chillersanim | If you call it in update, it will just place the object continuously instead of once. The position shoulnd't be affected. | |
| Aug 23, 2019 at 13:46 | comment | added | tmighty | Thank you. I guess I see now what the culprit is. I call your method on each Update, and you only do it once in OnEnable. Is it not allowed / ok to call it on each Update? I mean it's not economic, but I wanted to do it this way in order to test it comfortable while resizing my game window. | |
| Aug 23, 2019 at 8:43 | history | edited | Chillersanim | CC BY-SA 4.0 | Changed the usage of renderer to bounds |
| Aug 23, 2019 at 8:40 | comment | added | Chillersanim | So, I adapted the code and made it simpler to use. However, the way it works is still the same. On my pc it works. As for your code, you calculated the distance between the target and "this.transform", but later used Camera.main. Is the component attached to the camera? | |
| Aug 23, 2019 at 8:37 | history | edited | Chillersanim | CC BY-SA 4.0 | Changed the code to be directly usable. |
| Aug 22, 2019 at 14:39 | comment | added | Chillersanim | This evening Ill have access to a development environment again, then I'll test it out. Until now it was only theoretically working code. I'll update as soon as I have something functional. | |
| Aug 22, 2019 at 14:30 | comment | added | tmighty | Thank you, but it's still not right. Now the cube is even more "centered". I have also noticed that the code changes the cube's distance to the camera. Do you see any flaw in my distance calculation? | |
| Aug 21, 2019 at 18:32 | comment | added | Chillersanim | Hmmm, seems that the plane normals point to the inside of the frustum. I assumed they would point outward. I fixed it. | |
| Aug 21, 2019 at 18:31 | history | edited | Chillersanim | CC BY-SA 4.0 | Fixed normals that where the wrong way. |
| Aug 21, 2019 at 18:20 | comment | added | tmighty | I'm still having problems with the code. Now it places the cube inside the camera's view. I have added my code to the original posting. Do you see anything that I'm doing wrong in my call to your method? | |
| Aug 20, 2019 at 10:58 | comment | added | Chillersanim | I found a small error in my example code and fixed it. Furthermore, I incorporated the frustum left and added an example for the right hand side. I hope this works for you. | |
| Aug 20, 2019 at 10:57 | history | edited | Chillersanim | CC BY-SA 4.0 | Added references, added example for right bounds , fixed wrong value in example code. |
| Aug 19, 2019 at 23:51 | comment | added | tmighty | Could you please have a look again? I would also very much like to know how to make show it on the right instead of at the left. Thank you very much!! | |
| Aug 17, 2019 at 11:38 | comment | added | Chillersanim | Ah, that could be, because I used camera.transform.left, instead of the left of the frustum. I'm currently afk, I'll look into it when I'm back. | |
| Aug 17, 2019 at 1:05 | comment | added | tmighty | Do you think you could also show how to position the mesh on the right side instead of on the left side? Perhaps it's easy, but I don't see how. | |
| Aug 17, 2019 at 0:49 | comment | added | tmighty | ps: This works ALMOST correct for my case: (Bounds.size.x * 2). I'm dealing with a cube. There are just a few pixels visible of the cube. What might be the reason for these few pixels? | |
| Aug 17, 2019 at 0:33 | comment | added | tmighty | Thank you. Can you tell me what I should use for distance? Is this correct? float fDist = Mathf.Abs(Camera.main.transform.position.z - this.transform.position.z); I'm asking because there's still an offset: A part of the object is still visible. Not just a few pixel, but around 20% of the object's width. | |
| Aug 15, 2019 at 19:49 | comment | added | Chillersanim | Actually it shouldnt be divided by two, the method requires the full diameter. bounds.size.magnitude gives you the diameter. You pass this diameter to the method as goDiameter and it should work. | |
| Aug 15, 2019 at 16:53 | comment | added | tmighty | I am using Bounds. Could you please write out the magnitude / 2 code as I'm not perfectly sure how that should look? Thank you. | |
| Aug 15, 2019 at 16:21 | comment | added | Chillersanim | The easiest way would be to use the renderer.bounds. Then just take bounds.size.magnitude / 2 to get the half diameter. I couldn't test my approach above, as I'm not around my workplace atm. So please let me know if that helped or not. Might need to recheck the code. | |
| Aug 15, 2019 at 15:57 | comment | added | tmighty | I'm asking because unfortunately your approach doesn't work for me, and I'm trying to investigate where I may have gone wrong. | |
| Aug 15, 2019 at 15:47 | comment | added | tmighty | How would I get the mesh's diameter? | |
| Aug 15, 2019 at 9:52 | history | answered | Chillersanim | CC BY-SA 4.0 |