generated from krampus/template-godot4
Shot projection target is oriented to surface normal
This commit is contained in:
parent
424ee2f2ae
commit
902888be87
|
@ -73,6 +73,8 @@ func _process(_delta: float) -> void:
|
||||||
var pos := global_position
|
var pos := global_position
|
||||||
var vel := -global_basis.z * initial_speed
|
var vel := -global_basis.z * initial_speed
|
||||||
|
|
||||||
|
var final_normal: Vector3
|
||||||
|
|
||||||
for t in range(0, max_steps):
|
for t in range(0, max_steps):
|
||||||
# TODO: smooth curve with bezier handles
|
# TODO: smooth curve with bezier handles
|
||||||
path.curve.add_point(pos - global_position)
|
path.curve.add_point(pos - global_position)
|
||||||
|
@ -102,6 +104,7 @@ func _process(_delta: float) -> void:
|
||||||
vel = PUTT_ATTRITION * (vel - 2 * norm * vel.dot(norm))
|
vel = PUTT_ATTRITION * (vel - 2 * norm * vel.dot(norm))
|
||||||
else:
|
else:
|
||||||
# End projection!
|
# End projection!
|
||||||
|
final_normal = collision["normal"]
|
||||||
break
|
break
|
||||||
|
|
||||||
pos = next_pos
|
pos = next_pos
|
||||||
|
@ -109,12 +112,20 @@ func _process(_delta: float) -> void:
|
||||||
# Add terminal point (possibly collision point)
|
# Add terminal point (possibly collision point)
|
||||||
path.curve.add_point(pos - global_position)
|
path.curve.add_point(pos - global_position)
|
||||||
|
|
||||||
|
var child_basis := Basis.IDENTITY
|
||||||
|
if final_normal:
|
||||||
|
var up := final_normal.normalized()
|
||||||
|
var forward := Vector3(up.y, -up.x, 0)
|
||||||
|
var right := up.cross(forward).normalized()
|
||||||
|
forward = right.cross(up).normalized()
|
||||||
|
child_basis = Basis(right, up, forward)
|
||||||
|
|
||||||
# Reposition any children
|
# Reposition any children
|
||||||
for n: Node in get_children():
|
for n: Node in get_children():
|
||||||
if n is Node3D and n != path:
|
if n is Node3D and n != path:
|
||||||
var node_3d: Node3D = n
|
var node_3d: Node3D = n
|
||||||
node_3d.global_position = pos
|
node_3d.global_position = pos
|
||||||
node_3d.global_basis = Basis.IDENTITY
|
node_3d.global_basis = child_basis
|
||||||
|
|
||||||
(%DebugDraw as CanvasItem).queue_redraw()
|
(%DebugDraw as CanvasItem).queue_redraw()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue