Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "Above Timestamp Condition" #372

Open
tengkuizdihar opened this issue Jan 29, 2025 · 0 comments
Open

Add "Above Timestamp Condition" #372

tengkuizdihar opened this issue Jan 29, 2025 · 0 comments

Comments

@tengkuizdihar
Copy link

tengkuizdihar commented Jan 29, 2025

Is your feature request related to a problem? Please describe.
Currently there are no conditional expression that compares time + delay with value in the blackboard.

Describe the solution you'd like
I've created one, it looked like this

@tool
class_name DelayCondition extends ConditionLeaf


## This expression should result in float of unix time
## For example: get_state("last_aim_unix_time")
@export_placeholder(EXPRESSION_PLACEHOLDER) var operand_time_float: String = ""
## Time delay in second
## Will be compared to the result of operand_time_float
## Will not be checked if time is zero
@export_range(0.0, 100.0, 0.0, "or_greater", "hide_slider") var time_second: float = 1.0


@onready var _expression_time_float: Expression = _parse_expression(operand_time_float)


func tick(actor: Node, blackboard: Blackboard) -> int:
	var now = Time.get_unix_time_from_system()
	var time_raw: Variant = _expression_time_float.execute([], blackboard)

	if typeof(time_raw) != TYPE_FLOAT:
		push_error("The expression: \"%s\" does not result in float" % operand_time_float)
	if time_raw == 0.0:
		return FAILED
	if time_raw + time_second > now:
		return FAILED

	return SUCCESS

In the scene it looked like this (changed a bit for brevity):

[node name="CanShoot" type="Node" parent="<truncated>"]
script = ExtResource("14_heqx6")
operand_time_float = "get_value(\"last_aim_unix_time\")"
time_second = 1.5

Describe alternatives you've considered
None, for now.

Additional context
I'm using the behavioral tree instead of Finite State Machine for my main character's state. Currently I've implemented this condition for my main character's abilities. It goes like this:

  1. Player click fire <--- add to blackboard the timestamp when it first clicked using just_pressed and get_unix_time_from_system
  2. Must hold the fire for a duration of time <--- this is where this condition is being used
  3. After it's passed, then fire the gun in the direction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant