# Skating Away Help Please [SOLVED]

I have been playing this level for quite some time and couldn’t figure it out. Could anyone help me with solving it?

``````// Move to the red X mark while avoiding the yaks.
// use Vector.normalize(vector1) to create a vector in the same direction as vector1, but with a distance of 1
// use Vector.multiply(vector1, X) to create a vector in the same direction as vector1, but with its distance multiplied by X

// The point you want to get to.
var goalPoint = new Vector(78, 34);

while(true) {
// This creates a vector that will move you 10 meters toward the goalPoint
// First, create a vector from your hero to the goal point.
var goal = Vector.subtract(goalPoint, hero.pos);
// Then, normalize it into a 1m distance vector
goal = Vector.normalize(goal);
// Finally, multiply the 1m vector by 10, to get a 10m long vector.
goal = Vector.multiply(goal, 10);

// To avoid the yaks, if you get within 10 meters of a yak, you should vector away from it.
var yak = hero.findNearest(hero.findEnemies());
var distance = hero.distanceTo(yak);
if(distance < 10) {
// First, make a Vector from the yak to you
yak = Vector.subtract(hero.pos, yak);
// Now use Vector.normalize and Vector.multiply to make it 10m long
yak = Vector.normalize(yak);
// Once you have the 10m vector away from the yak, use Vector.add to add it to your goal vector!
yak = Vector.multiply(yak, 10);
goal = Vector.add(goal, yak);
}
// Finally, determine where to move by adding your goal vector to your current position.
var moveToPos = Vector.add(hero.pos, goal);
hero.move(moveToPos);
}

``````

Hey! Seems like your problem is that the variable yak is first declared as the entity object you found and then try to pass it to the following Vector.subtract function.

``````var yak = hero.findNearest(hero.findEnemies()); // 'It is not the position you get here!'
var distance = hero.distanceTo(yak);
if(distance < 10) {
// First, make a Vector from the yak to you
yak = Vector.subtract(hero.pos, yak); // 'It is not the position you use here!'
``````

Besides of that, everything seems fine i believe

1 Like

@Shurutsue is right, you need to use yak.pos.
Another thing, look carefully at these lines:

``````// First, make a Vector from the yak to you
yak = Vector.subtract(hero.pos, yak);
``````

from the yak, to you” Not the other way round.
I always used to find this hard. Don’t worry

Thank you I finished the level!!!

2 Likes

I don’t know what to use Vector.add to add.
Here is my code:

# The point you want to get to.

goalPoint = Vector(78, 34)

while True:
# This creates a vector that will move you 10 meters toward the goalPoint
# First, create a vector from your hero to the goal point.
goal = Vector.subtract(goalPoint, hero.pos)
# Then, normalize it into a 1m distance vector
goal = Vector.normalize(goal)
# Finally, multiply the 1m vector by 10, to get a 10m long vector.
goal = Vector.multiply(goal, 10)

``````# To avoid the yaks, if you get within 10 meters of a yak, you should vector away from it.
yak = hero.findNearest(hero.findEnemies())
distance = hero.distanceTo(yak)
if distance < 10:
# First, make a Vector from the yak to you
vector = Vector.subtract(hero.pos, distance)
# Now use Vector.normalize and Vector.multiply to make it 10m long
vector = Vector.normalize(vector)
vector = Vector.multiply(vector, 10)
# Once you have the 10m vector away from the yak, use Vector.add to add it to your goal vector!

pass

# Finally, determine where to move by adding your goal vector to your current position.
moveToPos = Vector.add(hero.pos, goal)
hero.move(moveToPos)``````

also, i don’t know how to format code properly, can you tell me please how to do it?

# The point you want to get to.

goalPoint = Vector(78, 34)

while True:
# This creates a vector that will move you 10 meters toward the goalPoint
# First, create a vector from your hero to the goal point.
goal = Vector.subtract(goalPoint, hero.pos)
# Then, normalize it into a 1m distance vector
goal = Vector.normalize(goal)
# Finally, multiply the 1m vector by 10, to get a 10m long vector.
goal = Vector.multiply(goal, 10)

``````# To avoid the yaks, if you get within 10 meters of a yak, you should vector away from it.
yak = hero.findNearest(hero.findEnemies())
distance = hero.distanceTo(yak)
if distance < 10:
# First, make a Vector from the yak to you
vector = Vector.subtract(hero.pos, distance)
# Now use Vector.normalize and Vector.multiply to make it 10m long
vector = Vector.normalize(vector)
vector = Vector.multiply(vector, 10)
# Once you have the 10m vector away from the yak, use Vector.add to add it to your goal vector!

pass

# Finally, determine where to move by adding your goal vector to your current position.
moveToPos = Vector.add(hero.pos, goal)
hero.move(moveToPos)
``````

i stiil can’t format it

Click on this button to format your code:

1 Like

thank you for that, here is my code now:

``````# Move to the red X mark while avoiding the yaks.
# use Vector.normalize(vector1) to create a vector in the same direction as vector1, but with a distance of 1
# use Vector.multiply(vector1, X) to create a vector in the same direction as vector1, but with its distance multiplied by X

# The point you want to get to.
goalPoint = Vector(78, 34)

while True:
# This creates a vector that will move you 10 meters toward the goalPoint
# First, create a vector from your hero to the goal point.
goal = Vector.subtract(goalPoint, hero.pos)
# Then, normalize it into a 1m distance vector
goal = Vector.normalize(goal)
# Finally, multiply the 1m vector by 10, to get a 10m long vector.
goal = Vector.multiply(goal, 10)

# To avoid the yaks, if you get within 10 meters of a yak, you should vector away from it.
yak = hero.findNearest(hero.findEnemies())
distance = hero.distanceTo(yak)
if distance < 10:
# First, make a Vector from the yak to you
vector = Vector.subtract(hero.pos, distance)
# Now use Vector.normalize and Vector.multiply to make it 10m long
vector = Vector.normalize(vector)
vector = Vector.multiply(vector, 10)
# Once you have the 10m vector away from the yak, use Vector.add to add it to your goal vector!
goal = Vector.add(goal, vector)
pass

# Finally, determine where to move by adding your goal vector to your current position.
moveToPos = Vector.add(hero.pos, goal)
hero.move(moveToPos)

``````

it now says that

``````hero.move(moveToPos)
``````

needs to have an ‘x’: number and ‘y’: number even though it was already there.

The code is good. But here you have to write goal, instead of distance.

1 Like

Im trying to load the level right now, but make sure that you have all your lines indented correctly (also im a huge fan of btd 6 too )

is there any more errors? My hero just absent-midedly walks into the first yak

I can see that, from your profile picture (i think)

Yea, can you post your updated code?

``````# Move to the red X mark while avoiding the yaks.
# use Vector.normalize(vector1) to create a vector in the same direction as vector1, but with a distance of 1
# use Vector.multiply(vector1, X) to create a vector in the same direction as vector1, but with its distance multiplied by X

# The point you want to get to.
goalPoint = Vector(78, 34)

while True:
# This creates a vector that will move you 10 meters toward the goalPoint
# First, create a vector from your hero to the goal point.
goal = Vector.subtract(goalPoint, hero.pos)
# Then, normalize it into a 1m distance vector
goal = Vector.normalize(goal)
# Finally, multiply the 1m vector by 10, to get a 10m long vector.
goal = Vector.multiply(goal, 10)

# To avoid the yaks, if you get within 10 meters of a yak, you should vector away from it.
yak = hero.findNearest(hero.findEnemies())
distance = hero.distanceTo(yak)
if distance < 10:
# First, make a Vector from the yak to you
vector = Vector.subtract(hero.pos, goal)
# Now use Vector.normalize and Vector.multiply to make it 10m long
vector = Vector.normalize(vector)
vector = Vector.multiply(vector, 10)
# Once you have the 10m vector away from the yak, use Vector.add to add it to your goal vector!
goal = Vector.add(goal, vector)
pass

# Finally, determine where to move by adding your goal vector to your current position.
moveToPos = Vector.add(hero.pos, goal)
hero.move(moveToPos)
``````

Almost the same except for `vector = Vector.subtract(hero.pos, goal)`
is different

1 Like

Here I did not put the `(goal)`maybe you would want to delete that

ok i’ll do that, i think it might work

1 Like

It might work. I have a completely different code, so I will try to help

my hero died in less than 7 seconds

1 Like