# Vector for Following a Circle [SOLVED]

All I want is to be able to walk in a circular path around a certain point. This seems so simple, but I don’t know what to do.
For a bit of context, I’m working on Backwoods Brawl, and trying to walk around the perimeter of the arena. I also want the soldiers I summon to walk in the opposite direction, but that can come later.
I looked at my code for Circle Walking, but I mirror the peasant’s vector, so it didn’t really help.
Any help?

I’m pretty sure you can do this without vectors. You should make an array of points you want to go. Something like this:

``````step = 0
loacations=[here you write points]
maximumPoints = len(locations)
While True:
hero.move({"x": locations[step], "y": locations[step+ 1]})
if hero.targetPos:
if hero.distanceTo(hero.targetPos) < 1:
step += 2
if step >= maximumPoints:
step = 0
``````

You can do the same for soldiers but with other points.

Sorry I have to do this…

*locations

My sincerest apologies,

Marmiteontoast

1 Like

If you really really want to correct other people, you can PM me and I will edit, please don’t post it in here because it is not related to the topic.

4 Likes

Vectors are points… and you can use the function provided in Library Tactician @FrostByte

Ok thanks

20 Because I can’t use that thing for special reasons wow it’s been so long since I had to type something like this

Vector is not a point. Vector is a direction.

I have smth like you need, I’ll see later. But as far as I remember I learnt it with drawing flavors on the level Forest flower grove
You can do it yourself)
P.S. I tried walking in circle on Backwoods Brawl, if I’m not mistaken, and the level arena wasn’t not literally circle…
P.P.S. Point could be a vector in some manner, as far as I remember hints of CoCo.

I’m currently only on the free version of Code Combat, so I can’t access that level. Could you perhaps send the generic code for it?

Okay, pretty good! The function is now mostly operational. There are, however, two problems.
First, I want to start at the top of the circle, so approximately 90°. Would I add something to the angle, or is there another way to do it?
Second, I haven’t found I way to get the soldier to go in a direction opposite to mine.
Here’s a bit of my code so far:

``````function location(index) {
var angle = Math.PI * 2 * index / 200;
var pos = {x: 60, y: 50};
pos.x += 40 * Math.cos(angle);
pos.y += 40 * Math.sin(angle);
return pos
}
``````

It’s straight from Library Tactician, but the position is returned and I made a couple of other adjustments.

``````const location = (x, y, r, a) => (new Vector(x + Math.sin(a) * r, y + Math.cos(a) * r));
``````

it should work better, it’s more code-efficient, and has more methods… and you reversed the sin and cos… don’t do that… sin is for x, cos is for y. Now it should start at the top, the top is 0°

And to make the soldier go to the opposite position, just do `([insert angle here] + 180) % 360`

I think that works, but I have to ask, how should a be incrimented. I’m having trouble incrementing it inside a `for` loop.

Ahhh, a is in radians… I forgot about that, I use Scratch too much use

``````const dtr = d => (d * Math.PI / 180);
``````

before passing it to the function

Ah, that worked perfectly!

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.