How to create a circular motion for an object moving in curved path?


I have curved path on which my player is steering through a spline nodes (using cat mull equation). Front face of path is circular and I want my player to make a circular motion on a particular keystroke. For my game scene I have aligned my game objects in following manner:

  • Spline Nodes
  • Player Mover which follows spline nodes and steer through a path (Parent)
  • Player (Child of Player Mover)
  • Camera(Child of Player and Grand child of Player Mover)

I managed to create a circular motion for a player using sin/cos equation for circle. But when circular motion starts, my player looses its contact with the transformation updates provided by parent object(player mover). It only follows the transformation along z axis and player even starts to phase out of the path when the path became curve.

Please suggest a solution. Thanks in advance.

Using following code to make a circular motion:

speed = (Mathf.PI * 2) / timeToCompleteCircle;
		float x;
		float y;
		switch (direction) {
		case "left":
			currentAngle += Time.deltaTime * speed;
			x = radius * Mathf.Cos (currentAngle);
			y = radius * Mathf.Sin (currentAngle);
			transform.position = new Vector3 (x, y, transform.position.z);

Do not use the "position " property as it sets the worldspace position of the object. Just use transform.localPosition instead.

transform.localPosition = new Vector3 (x, y, 0);