+2 votes

Hi All!
I have a 3d scene with a cannon in it that shoots a rigid body projectile. Once the projectile hits the ground, I want to measure the distance between the cannon (which is a static body) and the projectile (which is a rigid body), and pass the value into a variable.
I've read about a distance_to method in 2d. Is there something similar in 3d?

in Engine by (433 points)

1 Answer

+3 votes

It's the same in 3D.

Vector3.distance_to(Vector3)

translation, transform.origin and global_transform.origin can be used to get the Vector3's and try not to mix one with the other for example

translation.distance_to(other_node.global_transform.origin)

will not work properly if the nodes are parented either to each other or to the same spatial node that's not at (0,0,0).

by (3,219 points)
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.