Shoot laser around sphere

Hey there,

I have a character which is moving around a sphere (on the spheres surface).
I now wanted to create a laser to which allows the player to kill enemies which are also flying around the sphere.

Initially i thought abount using a raycast for that however, since a raycast is only a straigt line, the player shoots directly into space and not around the sphere.

I know thought that since i know in which direction the laser will fire and how long it will be just check wether there are any enemies on one of the coordinates, but I believe this might cost a bit too much performance (checking every object in the scene incl. their position etc.)

Is there any other way to achieve this ?

2 Answers

2

I found your question really interesting and have been following it since yesterday to see what kind of ideas would come up, since I never had to do any “orbital movement” like you need for your laser.

One way I would try to do this is using joints. You could attach a spring joint connecting the center of your world to your lasers, so the laser keeps a constant distance from the center of your planet. By adding a collider to your laser you would only have to create a script to handle the collision between a laser shot and an enemy.

I really wanted to see this working, so I built a small prototype and uploaded it to github. The prototype doesn’t handle the laser collision, just its movement around the planet.

I just started using unity, however what I would do is instantiate a bullet on the surface from the gun. Then rotate it around the planet? Just grab the radius of the planet and the height from the planet surface to gun height. In the update function you can get it to rotate with a function RotateAround. Pass it the transform.position of the object you want to rotate around.