Vectors and help

The help of the vector methods (Programmaticon V) needs some review.

Issue 1

The method has no examples, thus not making clear how to use it:

Based on this, I - as a newbie - would expect this to work:

m = Vector.magnitude(targetPos)

However, it only gives a cryptic error message (not very useful for a newbie):

After some trial and error and reading it turns out that correct format is:

m = targetPos.magnitude()           # no "vector" here

Affected methods: magnitude, copy, heading, x, y, z


Issue 2

The help is plainly confusing:

Hint: the correct format is:

myVec = Vector.rotate(targetPos, angle)

Affected methods: rotate, limit


Issue 3

The method is well explained, but it’s not in the format of the current language (e.g. in my case: Python):

Affected methods: add, distance, and almost all others…

1 Like

targetPos is likely to be a Vector as [].pos method returns a vector. So, you’ve been dealing with vectors longer than you realized. I haven’t played with Vector.magnitude() yet, however, so I can’t comment further.

Example 2: The example is correct. diff is a Vector and the angle is in radians. Math.PI * 2 = 360 degrees. Math.PI / 2 = 90 degrees turn, thus the variable name “tangent”. I agree, the title needs work:
Vector.rotate(theta, angle) would probably be better.

Example3: Agreed, that’s java. It is not difficult to translate that, however.

targetPos = self.getNearestEnemy().pos   
diff = Vector(5,5)
res = Vector.add(targetPos, diff)

I would note that the odds of folks still having access to getNearestEnemy() at this stage is fairly low. I’d suggest a slightly different example:

targetPos = self.findNearest(self.findEnemies())

or

res = Vector.add(self.pos, diff)

I just added a GitHub issue to work on this: https://github.com/codecombat/codecombat/issues/3110