0 votes

Having limited knowledge about 3D in general, I'm trying to get coordinates in relation to node B, from node A's point of view (in this case left side).

The plan is to make a crude avoidance mechanism which is why this needs to work in both example 1 & 2 and regardless which way node B or A is facing.

I failed to find a solution from reading the documentation, but I suspect a bit of simple math would do the job.

in Engine by (46 points)

1 Answer

0 votes

You tagged your question as 3D, but you are showing 2D examples. I know it's for illustration, but in 3D you are missing the Y coordinate, which determines where is up and down. If you don't mind, then your problem is 2D only using X and Z.

You can ignore the direction of both points, however if you do that you'll have a problem, because you need to figure out where to go, and continue going the same way over time. Left? Right? Only the direction of at least one of the points can fix that.

In 2D, finding the position of the red cross can be done this way:

# Assuming A and B are 2D coordinates

# Get direction from A to B
var direction = (B - A).normalized()

# Rotate 90 degrees... left or right?
# To decide that, make the angle positive or negative.
var lateral_direction = direction.rotated(PI/2.0)

# Calculate red cross position
var cross_pos = B + lateral_direction * some_distance

Transposing that in 3D depends on how you want it to behave with a third dimension, I would say that the up vector (Y) will come into play then, because the ground might not be flat.

by (28,791 points)

Thanks!
Adding a Vector3 to your solution seemed to do the trick.

var lat_dir = dir.rotated(Vector3(0,1,0),PI/2.0)

The game world is pretty flat so y-axis should not be a problem, although I am yet to test it with actual navigation.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.