#dynamically drawing a thick line in 3d space
1 messages · Page 1 of 1 (latest)
You basically need to use a different mesh.
One style that I like are ultra kills bullet tracers. It uses a thin quad mesh rotated around its relative forward so its up direction is always facing towards the camera. This way it has a cool pixel art in 3d aesthetic because the two ends of the tracers are clearly rectangular.
You probably want a capsule or some other tubular shape.
and how would i rotate it to the correct direction and make it go from point a to point b? (also hello fellow ultrakill fan)
You need to get the direction to the camera on the local z axis then rotate it so that it’s facing that direction
var current_forward = -basis.z
var current_up = basis.y
var cam_dir = position.direction_to(camera.position)
var z_comp = cam_dir.project(current_forward)
var tar_up = cam_dir - z_comp
var angle = current_up.signed_angle_to(tar_up, current_forward)
basis = basis.rotated(current_forward, angle)
I think that should work.
but point a isnt at the camera nor is it facing the camera, it’s just the position of an enemy
You want the whole object, to face the camera because it's a 2d object and if it doesnt face the camera you may not be able to see it. Maybe i didnt understand you question.
To make the object one method is to make a quad mesh with a specific width that faces the -z direction. Then when you create it you set it's length to the distance between point a and point b. It's offset to half the distance. and it's direction towards point b.
Ill try to mock up a script
var thickness = 2
func create_ray(point_a, point_b):
mesh = PlaneMesh.new()
var distance: float = point_a.distance_to(point_b)
mesh.size = Vector2(thickness, distance)
mesh.center_offset.z = - distance / 2
global_position = start_position
look_at(point_b)
I do not actually know if this script would work.
Also i'm assuming this script is on a MeshInstance
I've also fixed some issues in the script and the first script