Hello,
so i want to move an Object which is already constant moving up the Yaxis, but when i press left/right key then it should move to the pressed key direction in a circular way. Basically it should move like a circle from that position it was last. And here is my problem: when I press the left/arrow key it moves in a circular way but not from where my objects was last. It always jumps to the same position(it rotates around position 0,0).
My first inclination, if I understand you correctly, is to store a vector with the origin you want to rotate around, then add that point to your temp position.
Vector2 origin;
float radius;
//define these in some other place when the character starts moving in a circle
else{
timeCounter += Time.deltaTime * Input.GetAxis("Horizontal");
float x = Mathf.Cos(timeCounter)*radius+origin.x;
float y = Mathf.Sin(timeCounter)*radius+origin.y;
tempPosition = new Vector2(x, y);
transform.localPosition = (Vector3)tempPosition;
}
This would keep the player rotating around an origin specified with a radius “radius”.
Another option is to use an empty gameobject to define the center-point of the rotation with it’s position, and make the object-to-be-rotated-in-a-circle a child of this.
Now, you can change the transform.rotation component of this parent object, to rotate the child object around the center-point.
The most noticeable difference between this and the method Nomenokes suggested is: using this method the same face will always point towards the center. In other-words, the object itself will rotate once per “orbit”, like the moon around the earth (tidally locked). (Of course, an additional operation to the objects rotation, could change this, for either method.)