I made a post already, but it was quite undefined, so making another one. So like I said I’m trying to make a code for getting length and rotation of line between two points (start point is created then you press mouse button and end point is created then you release it). Like this: . - End point | . - Start point
And from this I want to get length between the points (so one “|”, of course I need it in Godot measurements, so meters) and direction (upwards, it would be best in degrees).
Please help, haha, I need a suggestion how could I do such a thing.
Use a.distance_to(b) for distance measuring, and a.angle_to_point(b) for angle measuring in radians. And you might want to convert radians to degrees using the rad_to_deg() function.
So I want to make a system which makes two points, like I said and I want them to be based on the direction you are looking at. So then you are holding down mouse and rotate the camera (change the direction your player is looking at) you are drawing a straight line (between your mouse and the position at which you started holding down the mouse). For this to work I need to somehow draw a 2d line based on your camera rotation and I can’t figure out how to.
Nope, didn’t succeed. At least I thought of more simplified description of what I’m trying to do: Add two points of which one is the middle of the screen right now and the other one is the position of the middle of the screen at the start (then mouse button was pressed).
Make sure you understand these code. Also, if you want to use your own scene for the points, you can always replace them as follows:
@export var my_point_scene: PackedScene
# This var will store the root node of your scene, so if the root node
# of your scene is of other types, such as "Sprite2D", ensure you replace
# the "Node2D" type annotation with the type you actually used.
var start_point: Node2D
func start(point: Vector2) -> void:
start_point = my_point_scene.instantiate()