47 lines
1.4 KiB
GDScript
47 lines
1.4 KiB
GDScript
@tool
|
|
extends Node
|
|
|
|
## ANGLES
|
|
|
|
# Check if a colliding body is aligned within a given angle of the object
|
|
# max_angle_diff --- note: set to 1 if angle won't be counted
|
|
# currently only works when objects are scaled (1,1,1)
|
|
func angle_velocity_aligned(source:Node, source_angle:Vector3, body:Node, max_angle_diff:Vector3):
|
|
var obj_direction = source.basis * source_angle
|
|
var player_direction = body.velocity.normalized()
|
|
var diff = abs(abs(obj_direction) - abs(player_direction))
|
|
if diff.x <= max_angle_diff.x and diff.y <= max_angle_diff.y and diff.z <= max_angle_diff.z:
|
|
return true
|
|
else:
|
|
return false
|
|
|
|
#pass in a dictornary of weighted random choices, returns id of selection
|
|
func weighted_random(choices):
|
|
var sum_of_choices = 0.0
|
|
|
|
#Get sum of all choices
|
|
for i in choices:
|
|
sum_of_choices += choices[i]
|
|
|
|
var random_number = randf_range(0,sum_of_choices)
|
|
print("----------------------------------------------------------------")
|
|
print("CHOICES: ",choices)
|
|
print("SUM OF CHOICES: ",sum_of_choices)
|
|
print("RANDOM NUMBER: ",random_number)
|
|
|
|
for i in choices:
|
|
if random_number < choices[i]:
|
|
print("SELECTION: ", i)
|
|
print("----------------------------------------------------------------")
|
|
return i
|
|
random_number -= choices[i]
|
|
|
|
func only_valid_chars(input_string: String) -> String:
|
|
var valid_chars = ""
|
|
|
|
for char in input_string:
|
|
if char.is_valid_identifier():
|
|
valid_chars += char
|
|
|
|
return valid_chars
|