- Home /
How to make a gameObject Transform Position move in a circle while making its Transform Position move forward?
I'm looking to adjust the Transform Position not the Transform Rotation. Thank You for your help.
Comment
Answer by Danief_ · Apr 09, 2019 at 07:46 PM
You could use two different pieces of code to manipulate the two movements. The movement doesn't need to be controlled from one central location. Something like the following: GameObject g;
void Start()
{
StartCoroutine(MoveCircularly());
StartCoroutine(MoveForward());
}
IEnumerator MoveForward()
{
while ( condition )
{
g.transform.Translate(Vector2.right);
yield return new WaitForEndOfFrame();
}
}
IEnumerator MoveCircularly()
{
while ( condition )
{
//move in a circle
yield return new WaitForEndOfFrame();
}
}
// I'm using Unity2D =)
// I'm trying to move the Transform.Position in a circle pattern and also move it forward.
// I'm not trying to move transform.rotation at all just the transform.position.
// This one moves in a circle pattern but unfortunately shakes violently which I don't want.
// Also it does not move forward which I do want it to do.
// $$anonymous$$ost importantly, I don't want it to immediately move on Start. I want it to move after something is true. When I put it on FixedUpdate it moved too quickly.
// Thank you for any help! =)
void Start()
{
StartCoroutine($$anonymous$$oveCircularly());
StartCoroutine($$anonymous$$oveForward());
}
IEnumerator $$anonymous$$oveForward()
{
while ( condition )
{
g.transform.Translate(Vector2.right);
yield return new WaitForEndOfFrame();
}
}
IEnumerator $$anonymous$$oveCircularly()
{
while ( condition )
{
//move in a circle
yield return new WaitForEndOfFrame();
}
}
I solved it by having one Game Object move in a circle and add a Game Object into the Game Object moving in a circle and have it move forward. That's the best I can do since IEnumerator wasn't working both functions at the same time for me.