# How do I move a 3d object along a generated circular loop?

Attention Topic was automatically imported from the old Question2Answer platform.

I can’t seem to find a complete, simple and implementable version of code for this.

I have an enemy and I want him to move in a loop, so he will return to his starting point. I want the loop to be in 3d and the loop can be generated with inputs eg a radius of 10 and movement speed of 2.

I’ve seen 2d loops I can’t quite get to work, I’ve looked into 3d curves and path/pathfollow but hit blocks with each.

Help me if you can please!! There must be a simple way to do this?

So I can’t say that this method is entirely bug free but it should at least give you a start. I have this in C# but I can probably figure out how to translate that to GDScript if you need me to.

`````` private Vector3 _velocity = Vector3.Zero;
private int Speed = 10;

public override void _Process(float delta)
{
Vector3 rotDegMob = RotationDegrees;
Vector3 currentDirection;

//rotate the mob slightly about the y axis
rotDegMob.y += 0.8f;
RotationDegrees = rotDegMob;

//Now update our direction from the Transform
currentDirection = Transform.basis.z;

_velocity.z = currentDirection.z * Speed;
_velocity.x = currentDirection.x * Speed;

_velocity = MoveAndSlide(_velocity, Vector3.Up);
}

``````