1

From the image below, I know points A and B and would like to move B by e degrees (around A with in a circle of radius AB) to a point C which I don't know over a period of time, say 2 seconds. How can this be done, preferably with a coroutine?

enter image description here

TenOutOfTen
  • 467
  • 6
  • 14
  • It seems as if the solution provided in [Rotate GameObject over time](https://stackoverflow.com/questions/37586407/rotate-gameobject-over-time) isn't really factoring the centre of the rotation circle, or is taking it as the origin or something (I don't really get it). For example, `B` rotating by `e˚` around `A` will end up at a different place from `B` rotating by `e˚` around `C`. The position of the centre is key. Unfortunately I don't have enough up votes to comment there. – TenOutOfTen Jun 11 '18 at 10:47
  • Simplest way to do it, is make `A` an empty `GameObject` Set it to be `B`'s parents, then Rotate `A` The same way shown in `Rotate GameObject over time` When your done rotating it, Unparent B and remove A. – AresCaelum Jun 11 '18 at 11:23
  • @Eddge In the long run I'll be doing several rotations around several different points, so the repeated parenting and unparenting for centres doesn't seem to be to appropriate for my situation. Most likely `rotateObject` function having factoring a centre (`Vector3`) parameter would be ideal for me. Just not sure how to get that done. – TenOutOfTen Jun 11 '18 at 11:32
  • https://docs.unity3d.com/ScriptReference/Transform.RotateAround.html, previous comment was without googling, This is the first link when I googled "How to rotate an object around a point in unity". It should do the same thing you are looking for, so on Object B, you pass it the location of A, the axis you want it to rotate around so `Vector3.Up` for example, and then your angle. – AresCaelum Jun 11 '18 at 11:40
  • 1
    @Eddge `RotateAround` can only be called from an `Update` method. – TenOutOfTen Jun 12 '18 at 16:19
  • Where do you see that(the link I shared doesn't say that)? There are several Unity Answers where they are using it in coroutines. – AresCaelum Jun 12 '18 at 16:32
  • just tested myself and it can be done in a coroutine. – AresCaelum Jun 12 '18 at 16:41
  • @Eddge I would really appreciate it if you could share your tested coroutine – TenOutOfTen Jun 12 '18 at 17:04
  • 1
    I am at work atm but the guise of it is: `IEnumerator orbit() { Vector3 rotationPoint = new Vector3(1,0,0); while(true) { transform.RotateAround(rotationPoint, Vector3.up, 90*Time.deltaTime); yield return null; // returns at the beginning of the frame. } }` I will post the version from my personal machine when I get home for the day. – AresCaelum Jun 12 '18 at 17:50

0 Answers0