#dynamically drawing a thick line in 3d space

1 messages · Page 1 of 1 (latest)

crystal lagoon
#

im making an enemy that draws a line and then moves across it (or, more realistically, makes a target position, draws a line to the target position and then dashes to it)
currently im using an immediatemesh to draw the line, but it’s not thick enough and i cant find how to make it thicker
how would i make it thicker?

short lily
#

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.

crystal lagoon
short lily
#

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.

crystal lagoon
short lily
#

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

crystal lagoon
#

ohhhh it's a flat mesh

#

ill try it out tomorrow