Hide seek behavior with only the vectors towards the enemy and the hiding spotCalculating a 2D Vector's Cross Product“for” loop in python-pygame does not break under an “if” statementSTL Sort use of Static Functioncalculate vector after rotating it towards another by angle θ in 3D spaceRay plane intersection finding direction vectorMutable structs in a vectorWrong repositioning circle after collision with segment with a vector algorithmC# and XNA — How to make 3d model follow another 3d model using lerpHave trouble with obstacle avoidance in matplotlibSKlearn: KDTree how to return nearest neighbour based on threshold (Python)
Is it a bad idea to plug the other end of ESD strap to wall ground?
Forgetting the musical notes while performing in concert
Why do I get negative height?
Processor speed limited at 0.4 Ghz
files created then deleted at every second in tmp directory
Do Iron Man suits sport waste management systems?
Do creatures with a listed speed of "0 ft., fly 30 ft. (hover)" ever touch the ground?
Should I tell management that I intend to leave due to bad software development practices?
Notepad++ delete until colon for every line with replace all
How can I prove that a state of equilibrium is unstable?
What is the opposite of "eschatology"?
Is "/bin/[.exe" a legitimate file? [Cygwin, Windows 10]
Where would I need my direct neural interface to be implanted?
Different meanings of こわい
In Bayesian inference, why are some terms dropped from the posterior predictive?
Finitely generated matrix groups whose eigenvalues are all algebraic
Why are UK visa biometrics appointments suspended at USCIS Application Support Centers?
What's the meaning of "Sollensaussagen"?
Can I hook these wires up to find the connection to a dead outlet?
Does int main() need a declaration on C++?
Machine learning testing data
How to enclose theorems and definition in rectangles?
What reasons are there for a Capitalist to oppose a 100% inheritance tax?
Am I breaking OOP practice with this architecture?
Hide seek behavior with only the vectors towards the enemy and the hiding spot
Calculating a 2D Vector's Cross Product“for” loop in python-pygame does not break under an “if” statementSTL Sort use of Static Functioncalculate vector after rotating it towards another by angle θ in 3D spaceRay plane intersection finding direction vectorMutable structs in a vectorWrong repositioning circle after collision with segment with a vector algorithmC# and XNA — How to make 3d model follow another 3d model using lerpHave trouble with obstacle avoidance in matplotlibSKlearn: KDTree how to return nearest neighbour based on threshold (Python)
For a pygame class, I am asked to implement various seek behaviors with limited information about the game world. Most behaviors have been easy to do, but I am blocked trying to implement the hide behavior with the information I have access to.
I am given two vectors and the position of an agent in the world. The first vector is the distance between the agent and the enemy it has to hide from. The second vector is the distance from the agent and the nearest column it can hide behind. Given this, I'd like to move the agent towards the column and make sure it stays hidden from the enemy.
In graphical term, I am trying to find the vector b
in this image, I have access to the vector u
and v
and I am trying to calculate the vector w
plus a scalar a
for the intended distance of from the column + its radius.
I currently have this code running, but it is obviously wrong as the vector I calculate is outside the bounds of the game world.
player_to_col_vector = (
col_distance[0] - enemy_distance[0],
col_distance[1] - enemy_distance[1],
)
normalized = 1 / sqrt(player_to_col_vector[0] ** 2 + player_to_col_vector[1] ** 2)
dx = normalized * acceptable_distance
dy = normalized * acceptable_distance
I think my issue is that I now have the vector wa
, but I have no idea how to find the b
vector from the information I have.
python vector
add a comment |
For a pygame class, I am asked to implement various seek behaviors with limited information about the game world. Most behaviors have been easy to do, but I am blocked trying to implement the hide behavior with the information I have access to.
I am given two vectors and the position of an agent in the world. The first vector is the distance between the agent and the enemy it has to hide from. The second vector is the distance from the agent and the nearest column it can hide behind. Given this, I'd like to move the agent towards the column and make sure it stays hidden from the enemy.
In graphical term, I am trying to find the vector b
in this image, I have access to the vector u
and v
and I am trying to calculate the vector w
plus a scalar a
for the intended distance of from the column + its radius.
I currently have this code running, but it is obviously wrong as the vector I calculate is outside the bounds of the game world.
player_to_col_vector = (
col_distance[0] - enemy_distance[0],
col_distance[1] - enemy_distance[1],
)
normalized = 1 / sqrt(player_to_col_vector[0] ** 2 + player_to_col_vector[1] ** 2)
dx = normalized * acceptable_distance
dy = normalized * acceptable_distance
I think my issue is that I now have the vector wa
, but I have no idea how to find the b
vector from the information I have.
python vector
add a comment |
For a pygame class, I am asked to implement various seek behaviors with limited information about the game world. Most behaviors have been easy to do, but I am blocked trying to implement the hide behavior with the information I have access to.
I am given two vectors and the position of an agent in the world. The first vector is the distance between the agent and the enemy it has to hide from. The second vector is the distance from the agent and the nearest column it can hide behind. Given this, I'd like to move the agent towards the column and make sure it stays hidden from the enemy.
In graphical term, I am trying to find the vector b
in this image, I have access to the vector u
and v
and I am trying to calculate the vector w
plus a scalar a
for the intended distance of from the column + its radius.
I currently have this code running, but it is obviously wrong as the vector I calculate is outside the bounds of the game world.
player_to_col_vector = (
col_distance[0] - enemy_distance[0],
col_distance[1] - enemy_distance[1],
)
normalized = 1 / sqrt(player_to_col_vector[0] ** 2 + player_to_col_vector[1] ** 2)
dx = normalized * acceptable_distance
dy = normalized * acceptable_distance
I think my issue is that I now have the vector wa
, but I have no idea how to find the b
vector from the information I have.
python vector
For a pygame class, I am asked to implement various seek behaviors with limited information about the game world. Most behaviors have been easy to do, but I am blocked trying to implement the hide behavior with the information I have access to.
I am given two vectors and the position of an agent in the world. The first vector is the distance between the agent and the enemy it has to hide from. The second vector is the distance from the agent and the nearest column it can hide behind. Given this, I'd like to move the agent towards the column and make sure it stays hidden from the enemy.
In graphical term, I am trying to find the vector b
in this image, I have access to the vector u
and v
and I am trying to calculate the vector w
plus a scalar a
for the intended distance of from the column + its radius.
I currently have this code running, but it is obviously wrong as the vector I calculate is outside the bounds of the game world.
player_to_col_vector = (
col_distance[0] - enemy_distance[0],
col_distance[1] - enemy_distance[1],
)
normalized = 1 / sqrt(player_to_col_vector[0] ** 2 + player_to_col_vector[1] ** 2)
dx = normalized * acceptable_distance
dy = normalized * acceptable_distance
I think my issue is that I now have the vector wa
, but I have no idea how to find the b
vector from the information I have.
python vector
python vector
edited Mar 8 at 21:22
GPierre
asked Mar 8 at 20:37
GPierreGPierre
559
559
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
I assume that acceptable_distance
corresponds to the size of the vector a in the image. So acceptable_distance
is the distance between C and D
The calculation of the normalized vector is wrong. normalized
is the reciprocal length of the vector from B to C:
normalized = 1 / sqrt(player_to_col_vector[0] ** 2 + player_to_col_vector[1] ** 2)
In the following lenBC
is the distance between B and C. dirBC
is a Unit vector (this means its length is 1) and is the direction form B to C:
lenBC = sqrt(player_to_col_vector[0] ** 2 + player_to_col_vector[1] ** 2)
dirBC = (player_to_col_vector[0] / lenBC, player_to_col_vector[1] / lenBC)
(dx, dy)
is the vector from C to D.
dx, dy = (dirBC[0] * acceptable_distance, dirBC[1] * acceptable_distance)
The vector b, which is equal the point D, is the sum of the vector v and the vector a:
bx, by = (col_distance[0] + dx, col_distance[1] + dy)
The vector from the point B
to D
is the sum of w
and a
:
BDx, BDy = (player_to_col_vector[0] + dx, player_to_col_vector[1] + dy)
Deleted, since the tag "pygame" was removed.
The above code does all the calculations. But note, in PyGame there is an much easier way to do this, by using pygame.math.Vector2
for calculations:
u = pygame.math.Vector2(enemy_distance)
v = pygame.math.Vector2(col_distance)
w = v - u
a = w.normalize() * acceptable_distance
b = v + a
Due to how the assignment has been made, we cannot import anything. The main code evaluates my code at run time and gives me some functions I can call by adding them to the top of my file. Vector math is not part of those functions sadly.
– GPierre
Mar 8 at 21:15
@GPierrepygame.math.Vector2
is part of PyGame. You tagged the question <pgame> all you've to isimport pygame
! Anyway the 1st part of the answer solves your issue with out any library functions.
– Rabbid76
Mar 8 at 21:16
I probably shouldn't have tagged pygame even though it's a pygame assignment. If we import anything in that assignment, it's an automatic 0 >.>
– GPierre
Mar 8 at 21:22
It works! Thanks a bunch
– GPierre
Mar 8 at 21:31
@GPierre You're welcome.
– Rabbid76
Mar 8 at 21:32
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55070658%2fhide-seek-behavior-with-only-the-vectors-towards-the-enemy-and-the-hiding-spot%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I assume that acceptable_distance
corresponds to the size of the vector a in the image. So acceptable_distance
is the distance between C and D
The calculation of the normalized vector is wrong. normalized
is the reciprocal length of the vector from B to C:
normalized = 1 / sqrt(player_to_col_vector[0] ** 2 + player_to_col_vector[1] ** 2)
In the following lenBC
is the distance between B and C. dirBC
is a Unit vector (this means its length is 1) and is the direction form B to C:
lenBC = sqrt(player_to_col_vector[0] ** 2 + player_to_col_vector[1] ** 2)
dirBC = (player_to_col_vector[0] / lenBC, player_to_col_vector[1] / lenBC)
(dx, dy)
is the vector from C to D.
dx, dy = (dirBC[0] * acceptable_distance, dirBC[1] * acceptable_distance)
The vector b, which is equal the point D, is the sum of the vector v and the vector a:
bx, by = (col_distance[0] + dx, col_distance[1] + dy)
The vector from the point B
to D
is the sum of w
and a
:
BDx, BDy = (player_to_col_vector[0] + dx, player_to_col_vector[1] + dy)
Deleted, since the tag "pygame" was removed.
The above code does all the calculations. But note, in PyGame there is an much easier way to do this, by using pygame.math.Vector2
for calculations:
u = pygame.math.Vector2(enemy_distance)
v = pygame.math.Vector2(col_distance)
w = v - u
a = w.normalize() * acceptable_distance
b = v + a
Due to how the assignment has been made, we cannot import anything. The main code evaluates my code at run time and gives me some functions I can call by adding them to the top of my file. Vector math is not part of those functions sadly.
– GPierre
Mar 8 at 21:15
@GPierrepygame.math.Vector2
is part of PyGame. You tagged the question <pgame> all you've to isimport pygame
! Anyway the 1st part of the answer solves your issue with out any library functions.
– Rabbid76
Mar 8 at 21:16
I probably shouldn't have tagged pygame even though it's a pygame assignment. If we import anything in that assignment, it's an automatic 0 >.>
– GPierre
Mar 8 at 21:22
It works! Thanks a bunch
– GPierre
Mar 8 at 21:31
@GPierre You're welcome.
– Rabbid76
Mar 8 at 21:32
add a comment |
I assume that acceptable_distance
corresponds to the size of the vector a in the image. So acceptable_distance
is the distance between C and D
The calculation of the normalized vector is wrong. normalized
is the reciprocal length of the vector from B to C:
normalized = 1 / sqrt(player_to_col_vector[0] ** 2 + player_to_col_vector[1] ** 2)
In the following lenBC
is the distance between B and C. dirBC
is a Unit vector (this means its length is 1) and is the direction form B to C:
lenBC = sqrt(player_to_col_vector[0] ** 2 + player_to_col_vector[1] ** 2)
dirBC = (player_to_col_vector[0] / lenBC, player_to_col_vector[1] / lenBC)
(dx, dy)
is the vector from C to D.
dx, dy = (dirBC[0] * acceptable_distance, dirBC[1] * acceptable_distance)
The vector b, which is equal the point D, is the sum of the vector v and the vector a:
bx, by = (col_distance[0] + dx, col_distance[1] + dy)
The vector from the point B
to D
is the sum of w
and a
:
BDx, BDy = (player_to_col_vector[0] + dx, player_to_col_vector[1] + dy)
Deleted, since the tag "pygame" was removed.
The above code does all the calculations. But note, in PyGame there is an much easier way to do this, by using pygame.math.Vector2
for calculations:
u = pygame.math.Vector2(enemy_distance)
v = pygame.math.Vector2(col_distance)
w = v - u
a = w.normalize() * acceptable_distance
b = v + a
Due to how the assignment has been made, we cannot import anything. The main code evaluates my code at run time and gives me some functions I can call by adding them to the top of my file. Vector math is not part of those functions sadly.
– GPierre
Mar 8 at 21:15
@GPierrepygame.math.Vector2
is part of PyGame. You tagged the question <pgame> all you've to isimport pygame
! Anyway the 1st part of the answer solves your issue with out any library functions.
– Rabbid76
Mar 8 at 21:16
I probably shouldn't have tagged pygame even though it's a pygame assignment. If we import anything in that assignment, it's an automatic 0 >.>
– GPierre
Mar 8 at 21:22
It works! Thanks a bunch
– GPierre
Mar 8 at 21:31
@GPierre You're welcome.
– Rabbid76
Mar 8 at 21:32
add a comment |
I assume that acceptable_distance
corresponds to the size of the vector a in the image. So acceptable_distance
is the distance between C and D
The calculation of the normalized vector is wrong. normalized
is the reciprocal length of the vector from B to C:
normalized = 1 / sqrt(player_to_col_vector[0] ** 2 + player_to_col_vector[1] ** 2)
In the following lenBC
is the distance between B and C. dirBC
is a Unit vector (this means its length is 1) and is the direction form B to C:
lenBC = sqrt(player_to_col_vector[0] ** 2 + player_to_col_vector[1] ** 2)
dirBC = (player_to_col_vector[0] / lenBC, player_to_col_vector[1] / lenBC)
(dx, dy)
is the vector from C to D.
dx, dy = (dirBC[0] * acceptable_distance, dirBC[1] * acceptable_distance)
The vector b, which is equal the point D, is the sum of the vector v and the vector a:
bx, by = (col_distance[0] + dx, col_distance[1] + dy)
The vector from the point B
to D
is the sum of w
and a
:
BDx, BDy = (player_to_col_vector[0] + dx, player_to_col_vector[1] + dy)
Deleted, since the tag "pygame" was removed.
The above code does all the calculations. But note, in PyGame there is an much easier way to do this, by using pygame.math.Vector2
for calculations:
u = pygame.math.Vector2(enemy_distance)
v = pygame.math.Vector2(col_distance)
w = v - u
a = w.normalize() * acceptable_distance
b = v + a
I assume that acceptable_distance
corresponds to the size of the vector a in the image. So acceptable_distance
is the distance between C and D
The calculation of the normalized vector is wrong. normalized
is the reciprocal length of the vector from B to C:
normalized = 1 / sqrt(player_to_col_vector[0] ** 2 + player_to_col_vector[1] ** 2)
In the following lenBC
is the distance between B and C. dirBC
is a Unit vector (this means its length is 1) and is the direction form B to C:
lenBC = sqrt(player_to_col_vector[0] ** 2 + player_to_col_vector[1] ** 2)
dirBC = (player_to_col_vector[0] / lenBC, player_to_col_vector[1] / lenBC)
(dx, dy)
is the vector from C to D.
dx, dy = (dirBC[0] * acceptable_distance, dirBC[1] * acceptable_distance)
The vector b, which is equal the point D, is the sum of the vector v and the vector a:
bx, by = (col_distance[0] + dx, col_distance[1] + dy)
The vector from the point B
to D
is the sum of w
and a
:
BDx, BDy = (player_to_col_vector[0] + dx, player_to_col_vector[1] + dy)
Deleted, since the tag "pygame" was removed.
The above code does all the calculations. But note, in PyGame there is an much easier way to do this, by using pygame.math.Vector2
for calculations:
u = pygame.math.Vector2(enemy_distance)
v = pygame.math.Vector2(col_distance)
w = v - u
a = w.normalize() * acceptable_distance
b = v + a
edited Mar 8 at 21:24
answered Mar 8 at 20:48
Rabbid76Rabbid76
42.9k123354
42.9k123354
Due to how the assignment has been made, we cannot import anything. The main code evaluates my code at run time and gives me some functions I can call by adding them to the top of my file. Vector math is not part of those functions sadly.
– GPierre
Mar 8 at 21:15
@GPierrepygame.math.Vector2
is part of PyGame. You tagged the question <pgame> all you've to isimport pygame
! Anyway the 1st part of the answer solves your issue with out any library functions.
– Rabbid76
Mar 8 at 21:16
I probably shouldn't have tagged pygame even though it's a pygame assignment. If we import anything in that assignment, it's an automatic 0 >.>
– GPierre
Mar 8 at 21:22
It works! Thanks a bunch
– GPierre
Mar 8 at 21:31
@GPierre You're welcome.
– Rabbid76
Mar 8 at 21:32
add a comment |
Due to how the assignment has been made, we cannot import anything. The main code evaluates my code at run time and gives me some functions I can call by adding them to the top of my file. Vector math is not part of those functions sadly.
– GPierre
Mar 8 at 21:15
@GPierrepygame.math.Vector2
is part of PyGame. You tagged the question <pgame> all you've to isimport pygame
! Anyway the 1st part of the answer solves your issue with out any library functions.
– Rabbid76
Mar 8 at 21:16
I probably shouldn't have tagged pygame even though it's a pygame assignment. If we import anything in that assignment, it's an automatic 0 >.>
– GPierre
Mar 8 at 21:22
It works! Thanks a bunch
– GPierre
Mar 8 at 21:31
@GPierre You're welcome.
– Rabbid76
Mar 8 at 21:32
Due to how the assignment has been made, we cannot import anything. The main code evaluates my code at run time and gives me some functions I can call by adding them to the top of my file. Vector math is not part of those functions sadly.
– GPierre
Mar 8 at 21:15
Due to how the assignment has been made, we cannot import anything. The main code evaluates my code at run time and gives me some functions I can call by adding them to the top of my file. Vector math is not part of those functions sadly.
– GPierre
Mar 8 at 21:15
@GPierre
pygame.math.Vector2
is part of PyGame. You tagged the question <pgame> all you've to is import pygame
! Anyway the 1st part of the answer solves your issue with out any library functions.– Rabbid76
Mar 8 at 21:16
@GPierre
pygame.math.Vector2
is part of PyGame. You tagged the question <pgame> all you've to is import pygame
! Anyway the 1st part of the answer solves your issue with out any library functions.– Rabbid76
Mar 8 at 21:16
I probably shouldn't have tagged pygame even though it's a pygame assignment. If we import anything in that assignment, it's an automatic 0 >.>
– GPierre
Mar 8 at 21:22
I probably shouldn't have tagged pygame even though it's a pygame assignment. If we import anything in that assignment, it's an automatic 0 >.>
– GPierre
Mar 8 at 21:22
It works! Thanks a bunch
– GPierre
Mar 8 at 21:31
It works! Thanks a bunch
– GPierre
Mar 8 at 21:31
@GPierre You're welcome.
– Rabbid76
Mar 8 at 21:32
@GPierre You're welcome.
– Rabbid76
Mar 8 at 21:32
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55070658%2fhide-seek-behavior-with-only-the-vectors-towards-the-enemy-and-the-hiding-spot%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown