I currently have a ship that can orbit around a sphere freely controlled by a joystick. There is a separate joystick that controls the gun and starts shooting when it is touched.

Right now the bullets start shooting and then orbit the sphere until their lifetime has elapsed. Instead of having them orbit the sphere I want them to orbit for maybe the first half of their life and then shoot off into space. Does that make sense?

It would give the effect of a kind of glancing off the atmosphere, instead of staying in orbit for the whole time.

I am working in Unity3D and using the RotateAround() method to get the bullets to orbit. I'm thinking I need to take a snapshot of there position at half life, and then figure out the vector that would shoot them off into space. If someone could help me get going in the right direction with that, that would be great!

  • 1
    \$\begingroup\$ You are in the right direction. When the bullet reaches its half-life, You should take the current position and speed of the bullet (actually, the current velocity vector is also good, if you can get that from somewhere), and stop the rotation. I don't know Unity, but maybe stopping the RotateAround and/or setting the bullet's acceleration to zero will stop it from going around a circle. Once the centripetal acceleration is zero, the bullet will shoot out in a straight line. \$\endgroup\$
    – Marton
    Commented Feb 27, 2013 at 13:35
  • 2
    \$\begingroup\$ I'm working on a similar idea, but I'm doing all the work in code (AS3). The ship can be in orbit or not, but that won't affect the shots - the shots are affected by the gravity of the planet, their vector. Glancing shot is only bent a small amount, too close to the planet and it falls in. If you have it transition from RotateAround() to vector, it might look a little odd - circle arc to straight line. You might want to do a gravity calc to smooth the trajectory of the shot \$\endgroup\$
    – Gone3d
    Commented Feb 27, 2013 at 13:49

1 Answer 1


I assume you have a separate routine that handles the behavior of the bullet, in which case you keep a timer variable(your halflife) that you reduce in the FixedUpdate method, and once it reaches zero then you change the behavior from doing a RotateAround to simply translating it according to the tangent to the planet multiplied by the current speed of the bullet, both of which you store at the instant that the timer ticks down to zero.

The tangent vector should be essentially the current transform.forward vector of the bullet gameobject whereas the speed would be the arclength traversed divided by the delta time of the FixedUpdate(unless of course you already have some constant speed in radians/second that you multiply by the FixedUpdate elapsed time). Arclength/sec would be the angle(in radians) that the bullet rotates/second * the distance from the center of the planet to the center of your bullet(the radius).

Edit: I should mention that this will not work if you currently are utilizing the physics engine to handle any aspects of the motion which it seems you aren't from the way you phrased the question.

Implementation: 1)Create a public variable in the bullet routine to store 'speed' so that it can be set in the prefab of the bullet gameObject. Also have an escape time(or distance if you prefer) variable and a boolean to determine if it is still rotating or translating.

2)In the rotate phase of your update the radians to RotateAround should be (speed * elapsedTime) / radius of sphere

3)Once the escape timer(or distance) is reached, set the boolean flag to indicate that you are no longer rotating. Now simply use the transform.forward vector multiplied by the speed * elapsed time to translate the bullet.

  • \$\begingroup\$ in the case he was using physics he could simply apply and impluse to the bullet in the tanget direction. I don't think so anyway, because he's rotating the object through RotateAround \$\endgroup\$
    – Heisenbug
    Commented Feb 27, 2013 at 15:23
  • \$\begingroup\$ Yea I am not using the physics engine, just manipulating the transform... And yes in my update() method I am detecting when the halflife has been reached, and then trying to just move it along a certain vector but I can't seem to figure out that "new" tangent vector correctly... You mention arclength, is that referring to how far the bullet has gone from it's origination point? If so, that may be a better way to determine its halflife (although I'm not sure how to determine that length...) \$\endgroup\$
    – DRiFTy
    Commented Feb 27, 2013 at 15:42
  • \$\begingroup\$ probably the object forward dir is(or should be) tangent to the planet it self. When halflife is reached you can stop rotating and moving the object forward: transform.translate(transform.forward * speed * Time.deltaTime); \$\endgroup\$
    – Heisenbug
    Commented Feb 27, 2013 at 15:50
  • \$\begingroup\$ @Heisenbug yes that is what I described above. If he is using RotateAround then the transform.forward vector should already be tangential to the sphere unless there is some other rotation happening. I've edited my response to include more details about implementation. \$\endgroup\$
    – RobCurr
    Commented Feb 27, 2013 at 16:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .