- Home /
Camera.WorldToScreenPoint Equivalent
So I have a number of Objects on a sphere with unique rotations. Each object have a Vector2 velocity that determines its direction and movement around the sphere My code is based off this post: http://answers.unity3d.com/questions/41050/how-can-i-make-movement-on-a-sphere.html So I want my objects to bounce off each other semi realisticly the math behind this has me stumped
One thing that gets very close to working is taking the screen position of the object the camera is attached to and the screen position of the other object colliding, then getting the angle between the two screen positions and changing the velocity to the Cosine and Sine of that angle.
BUT.. not every object can have a camera because its severely inefficient.
So my question is how could I use just math to accomplish the same effect of Camera.WorldToScreenPoint?
It may not be so inefficient as I think if I don't render anything on the camera. But it might be. Who knows? Still if you have a solution it would be much appreciated because I want to make this game for mobile and every optimization counts.
A buddy of $$anonymous$$e pointed out that the play-field and type is very similar to Super Stardust for Playstation 3. That game looks pretty sweet, I havn't played it but I watched a couple videos on Youtube. The asteroid co$$anonymous$$g in from the side and breaking apart on the play-field is amazing to me. Perhaps that game will be my inspiration for now. It almost looks like the asteroids are $$anonymous$$arching Cubes, I'll have to look into implementing some sort of procedurally generated asteroids myself. But first I better figure out a more efficient way to have collisions happen naturally on the sphere shape play-field.
Answer by cjdev · Jan 18, 2016 at 12:42 AM
The way that method works is by multiplying matrices together, specifically the model, view, and projection matrices (MVP). This is done quite often in the GPU by OpenGL or DirectX, just about every frame for every pixel actually, so it's a fairly common problem to solve. I would give you some example code but honestly I get a headache every time I see a matrix. There's a good answer here that might get you started though.